#logging #setup #structured #log #json-logging

slog-kickstarter

builder to easily setup the slog logging ecosystem

2 unstable releases

0.2.0 Oct 2, 2020
0.1.0 Jul 6, 2020

#623 in Debugging

MIT/Apache

13KB
109 lines

Rust build crates.io badge docs.rs badge

Slog Kickstarter 🚀

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"));
}

Dependencies

~5–15MB
~166K SLoC