Crate fil_logger
source · [−]Expand description
The logging level can be changed by the RUST_LOG
environment variable just like
env_logger
.
Example
use log::{trace, debug, info, warn, error};
fil_logger::init();
trace!("some tracing");
debug!("debug information");
info!("normal information");
warn!("a warning");
error!("error!");
The default output looks like this (with log level debug):
2019-11-11T21:04:25.685 DEBUG simple > debug information
2019-11-11T21:04:25.685 INFO simple > normal information
2019-11-11T21:04:25.685 WARN simple > a warning
2019-11-11T21:04:25.685 ERROR simple > error!
It is also possible to log as JSON, which is more verbose and contains the filename and line
number as additional information. To enable it, set the environment variable
GOLOG_LOG_FMT=json
:
{“level”:“debug”,“ts”:“2019-11-11T21:06:45.401+0100”,“logger”:“simple”,“caller”:“examples/simple.rs:37”,“,sg”:“debug information”} {“level”:“info”,“ts”:“2019-11-11T21:06:45.401+0100”,“logger”:“simple”,“caller”:“examples/simple.rs:38”,“msg”:“//! normal information”} {“level”:“warn”,“ts”:“2019-11-11T21:06:45.401+0100”,“logger”:“simple”,“caller”:“examples/simple.rs:39”,“msg”:“//! a warning”} {“level”:“error”,“ts”:“2019-11-11T21:06:45.401+0100”,“logger”:“simple”,“caller”:“examples/simple.rs:40”,“msg”:“error!”}
Structs
LogWriter
that accepts an open File
Functions
std::fs::File
.