twyg

A tiny logging setup for Rust applications

I got used to logging my apps in Clojure with Twig, in LFE with Logjam, and in Go with zylog, so here this is for Rust.

Usage

First, update your Cargo.tomls dependencies section:

toml [dependencies] twyg = "0.1.8"

I like to put my logging setup in YAML config files for my apps, but however you prefer to store your config, you'll next need to populate the twyg::LoggerOpts struct for your preferred mechanism:

```rust use twyg;

let opts = twyg::LoggerOpts{ coloured: true, file: None, level: String::from("debug"), report_caller: true, };

match twyg::setuplogger(&opts) { Ok() => {}, Err(error) => { panic!("Could not setup logger: {:?}", error) }, }; ```

The supported options are:

Once the setup function has been called, all subsequent calls to the standard Rust logging macros will use this setup, providing output like the following:

The output in the screenshot above (click for a full-sized view) is from running the demos in the examples directory.

Config

Use with the config library is seamless:

  1. Set up some YAML:

    yaml logging: coloured: true level: debug report_caller: true

  2. Add an entry to your config struct:

    ```rust

    [derive(Debug, Deserialize)]

    pub struct YourAppConfig { ... pub logging: twyg::LoggerOpts, ... } ```

  3. Create a constructor for YourAppConfig (see config library docs and examples)

  4. Build your config:

    rust let cfg = YourAppConfig::default().unwrap();

  5. Pass the logging config to twyg:

    rust match twyg::setup_logger(&cfg.logging) { Ok(_) => {} Err(error) => panic!("Could not setup logger: {:?}", error), };

License

Copyright © 2020-2021, Oxur Group

Apache License, Version 2.0