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:
§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§
- Returns a
env_logger::Builder
that is configured to usecrate
formatting for its output. - builderDeprecatedDeprecated. Use
default_builder
instead (see alsobasic_builder
) - Opinionated builder, with
colog
defaults. - Convenience function to create binding formatter closure
- Convenience function to initialize logging.