Expand description
A minimal and pretty logger for the log
crate.
To initialize it, call the init()
function.
use log::LevelFilter;
pretty_logging::init(LevelFilter::Info, []);
log::trace!("Hello pretty logger!");
log::debug!("Hello pretty logger!");
log::info!("Hello pretty logger!");
log::warn!("Hello pretty logger!");
log::error!("Hello pretty logger!");
panic!("Hello pretty logger!");
The init()
function spawns a thread which reads all incoming log messages and writes them
to the standard/error output. It holds a lock on the standard output to ensure that log
messages are printed in the order they are received, so once the logger is initialized, you
must avoid using println!
and eprintln!
.
You should note that when using this logger, the init()
function will set a custom panic
hook, which will override any previous panic hooks set. If you use custom panic hooks, make
sure to set them after init()
is called.
Functionsยง
- init
- Initializes the logger. This function spawns a thread to read log messages and write them to the appropriate output without blocking the current task.