Crate colog

source ·
Expand description

§Colog: Simple colored logger for rust

The colog library is a simple formatter backend for the standard rust logging system (in the log crate).

For convenience, colog provides utility functions to help initialize logging, while using some reasonable defaults.

All these defaults can be controlled, using a few more lines of code.

Example code:

  • examples/simple.rs (minimal example)
  • examples/levels.rs (custom log levels)

§Minimal example

use log::{error, warn, info, debug, trace};

// Quick start: use default initialization
colog::init();

error!("error message");
error!("error with fmt: {}", 42);
warn!("warn message");
info!("info message");
debug!("debug message"); // not printed (LogLevel::Info is the default level)
trace!("trace message"); // not printed (LogLevel::Info is the default level)

// notice how multi-line comments are handled gracefully
info!("multi line demonstration\nhere");
info!("more\nmulti\nline\nhere\nhere");

This results in the following terminal output:

demo screenshot from terminal

§Custom styling

All the styling of colog can be overriden.

The styling is provided by the trait CologStyle, which provides default implementations for all methods, resulting in the default colog style.

Example code:

  • examples/custom-level-colors.rs
  • examples/custom-level-tokens.rs
  • examples/custom-level-prefix.rs

Modules§

  • Functions and types for formatting log messages

Functions§