twyg 0.1.3

A tiny logging setup for Rust applications
Documentation

twyg

A tiny logging setup for Rust applications

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

Usage

First, update your Cargo.tomls dependencies section:

[dependencies]
twyg = "0.1.3"

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:

use twyg;

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

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

The supported options are:

  • colored: setting to false will disable ANIS colors in the logging output
  • file: provide a path to a file, and output will be logged there too
  • level: case-insensitive logging level
  • report_caller: setting to true will output the filename and line number where the logging call was made

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

The output in the screenshot above (click for a a full-sized view) is from running the little demo in main.rs.