17 unstable releases (3 breaking)

0.4.1 Jan 4, 2024
0.3.0 Jan 2, 2024
0.2.0 Mar 11, 2023
0.1.10 Nov 8, 2022
0.1.7 Mar 4, 2020

#287 in Development tools

Download history 4/week @ 2024-02-16 34/week @ 2024-02-23 22/week @ 2024-03-01 35/week @ 2024-03-29 5/week @ 2024-04-05 142/week @ 2024-04-12 9/week @ 2024-04-19 2/week @ 2024-04-26

167 downloads per month
Used in 7 crates (6 directly)


234 lines


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's something similar for Rust.

Version warnings:

  • v0.3 - A regression was introduced due to the move away from the unsupported (and insecure) colors library whereby one could no longer disable ANSI colour of logged output.
  • v0.4 - Due to the more complex nature of OwoColors, a major code refactor was required to fix the colour regression of v0.3, and as part of that several breaking changes were introduced, including a struct raname, new fields, etc.


First, update your Cargo.tomls dependencies section:

twyg = "0.4"

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::Opts struct for your preferred mechanism:

use twyg::{self, level};

let opts = twyg::Opts{
    coloured: true,
    level: level::debug(),
    report_caller: true,


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

The supported options are:

  • coloured: setting to false will disable ANIS colours 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 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.


Use with the config library is seamless:

  1. Set up some YAML:

        coloured: true
        level: debug
        report_caller: true
  2. Add an entry to your config struct:

    #[derive(Debug, Deserialize)]
    pub struct YourAppConfig {
        pub logging: twyg::Opts,
  3. Create a constructor for YourAppConfig (see config library docs and examples)

  4. Build your config:

    let cfg = YourAppConfig::default().unwrap();
  5. Pass the logging config to twyg:

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


Copyright © 2020-2024, Oxur Group

Apache License, Version 2.0


~101K SLoC