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§

format
Functions and types for formatting log messages

Functions§

basic_builder
Returns a env_logger::Builder that is configured to use crate formatting for its output.
builderDeprecated
Deprecated. Use default_builder instead (see also basic_builder)
default_builder
Opinionated builder, with colog defaults.
formatter
Convenience function to create binding formatter closure
init
Convenience function to initialize logging.