slog-kickstarter

Crates.ioslog-kickstarter
lib.rsslog-kickstarter
version0.2.0
sourcesrc
created_at2020-07-06 17:45:21.113144
updated_at2020-10-02 12:23:16.429997
descriptionbuilder to easily setup the slog logging ecosystem
homepagehttps://github.com/elmarx/slog-kickstarter
repositoryhttps://github.com/elmarx/slog-kickstarter
max_upload_size
id262033
size37,690
Elmar Athmer (elmarx)

documentation

README

Rust build crates.io badge docs.rs badge

Slog Kickstarter :rocket:

Builder to setup slog easily.

Slog is really great, but to leverage it's features and flexibility, it requires more setup than importing a module and calling a function (to be precise, it requires about 163 lines of code ;)).

Structured logging is great. You should not postpone introducing logging, but integrate it from the beginning, because retrofitting slog could require lots of changes. That's where Slog Kickstarter comes into play.

Features

  • switch between JSON-logging and (compacted) terminal output via environment-variable (RUST_LOG_JSON=1)
  • per-module debug-level (via with_debug_log_for()) — i.e. enable debugging for your own modules, but ignore debug-logs from 3rd-party crates
  • logging configuration via RUST_LOG=…, as known from env_logger (implemented by slog-envlogger), all preconfigured
  • log support by default (unless explicitly disabled)

Usage

See basic.rs for a running example, and full.rs for all features.

use slog::{o, slog_info};
use slog_kickstarter::SlogKickstarter;

fn main() {
    // initialize a root logger
    let root_logger = SlogKickstarter::new("logging-example").init();

    // slog supports string formatting, and additional structured fields
    slog_info!(root_logger, "Hello World!"; o!("type" => "example"));
}
Commit count: 13

cargo fmt