#slog #env

slog-env-cfg

Opinionated slog drains builder, configurable via env vars

10 releases (5 breaking)

✓ Uses Rust 2018 edition

new 0.6.0 Oct 11, 2019
0.5.0 Oct 8, 2019
0.4.0 Oct 7, 2019
0.3.0 Oct 7, 2019
0.1.3 May 31, 2019

#106 in Debugging

Download history 10/week @ 2019-06-28 15/week @ 2019-07-05 10/week @ 2019-07-12 1/week @ 2019-07-19 8/week @ 2019-07-26 15/week @ 2019-08-02 11/week @ 2019-08-09 11/week @ 2019-08-23 20/week @ 2019-08-30 16/week @ 2019-09-06 12/week @ 2019-09-13 31/week @ 2019-09-20 11/week @ 2019-09-27 79/week @ 2019-10-04

74 downloads per month

MIT license

19KB
437 lines

slog-env-cfg

crates.io docs.rs Build Status

Opinionated slog drains builder, configurable via env vars.

Description

This crate builds an slog Drain that writes to stdout. It's designed to be easy to use and with sane defaults. The format of the log records is configurable at runtime via LOG_FORMAT environment variable.

Possible values for LOG_FORMAT are:

  • terminal (default)
  • json

The idea is that in development environment, where you just run the executable manually and in the absence of centralized logging, you would rely on human-readable log output. At deployment, on the contrary, centralized logging system can make use of JSON-formatted logs, so the LOG_FORMAT=json can be set. The configuration is at runtime, so you only need to manage a single build artifact for both use cases.

This crate aims to be an opinionated solution, and no other configuration is available so far. Yet, I'm open to adding other tweaks if they're justified.

Usage

Here's a minimal complete main.rs example:

use slog::{info, o};

fn main() {
    let drain = slog_env_cfg::logger_from_env(o!()).expect("initialization error");
    info!(root, "formatted: {}", 1; "log-key" => true);
}

Dependencies

~4MB
~87K SLoC