[][src]Crate emit

Structured application logging.

This module provides:

The emit macros are "structured" versions of the ones in the widely-used log crate. The log crate doesn't preserve the structure of the events that are written through it. For example:

This example is not tested
info!("Hello, {}!", env::var("USERNAME").unwrap());

This writes "Hello, nblumhardt!" to the log as an block of text, which can't later be broken apart to reveal the username except with regular expressions.

The arguments passed to emit are named:

This example is not tested
info!("Hello, {}!", user: env::var("USERNAME").unwrap());

This event can be rendered into text identically to the log example, but structured data collectors also capture the aguments as a key/value property pairs.

{
  "@t": "2016-03-17T00:17:01.333Z",
  "@mt": "Hello, {user}!",
  "user": "nblumhardt",
  "target": "example_app"
}

Back-ends like Elasticsearch, Seq, and Splunk use these in queries such as user == "nblumhardt" without up-front log parsing.

Arguments are captured using serde, so there's the potential for complex values to be logged so long as they're serde::ser::Serialize.

Further, because the template (format) itself is captured, it can be hashed to compute an "event type" for precisely finding all occurrences of the event regardless of the value of the user argument.

Examples

The example below writes events to stdout.

#[macro_use]
extern crate emit;

use std::env;
use emit::PipelineBuilder;
use emit::collectors::stdio::StdioCollector;
use emit::formatters::raw::RawFormatter;

fn main() {
    let _flush = PipelineBuilder::new()
        .write_to(StdioCollector::new(RawFormatter::new()))
        .init();

    info!("Hello, {}!", name: env::var("USERNAME").unwrap_or("User".to_string()));
}

Output:

emit 2016-03-24T05:03:36Z Hello, {name}!
  name: "nblumhardt"
  target: "example_app"

Re-exports

pub use pipeline::builder::PipelineBuilder;

Modules

collectors
enrichers
events
formatters
pipeline

An asynchronous/buffered log event pipeline from producers to a single dispatching consumer. Currently based on std::sync::mpsc, but highly likely this will change.

templates

Macros

debug

Emit a debugging event to the ambient pipeline.

emit

Emit an event to the ambient pipeline.

error

Emit an error event to the ambient pipeline.

info

Emit an informational event to the ambient pipeline.

trace

Emit a trace event to the ambient pipeline.

warn

Emit a warning event to the ambient pipeline.

Enums

LogLevel
LogLevelFilter