Struct tracing_log::log_tracer::LogTracer
source · pub struct LogTracer { /* private fields */ }
Expand description
A simple “logger” that converts all log records into tracing
Event
s.
Implementations§
source§impl LogTracer
impl LogTracer
sourcepub fn builder() -> Builder
pub fn builder() -> Builder
Returns a builder that allows customizing a LogTracer
and setting it
the default logger.
For example:
use tracing_log::LogTracer;
use log;
LogTracer::builder()
.ignore_crate("foo") // suppose the `foo` crate is using `tracing`'s log feature
.with_max_level(log::LevelFilter::Info)
.init()?;
// will be available for Subscribers as a tracing Event
log::info!("an example info log");
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new LogTracer
that can then be used as a logger for the log
crate.
It is generally simpler to use the init
or init_with_filter
methods
which will create the LogTracer
and set it as the global logger.
Logger setup without the initialization methods can be done with:
use tracing_log::LogTracer;
use log;
let logger = LogTracer::new();
log::set_boxed_logger(Box::new(logger))?;
log::set_max_level(log::LevelFilter::Trace);
// will be available for Subscribers as a tracing Event
log::trace!("an example trace log");
sourcepub fn init_with_filter(level: LevelFilter) -> Result<(), SetLoggerError>
pub fn init_with_filter(level: LevelFilter) -> Result<(), SetLoggerError>
Sets up LogTracer
as global logger for the log
crate,
with the given level as max level filter.
Setting a global logger can only be done once.
The builder
function can be used to customize the LogTracer
before
initializing it.
sourcepub fn init() -> Result<(), SetLoggerError>
pub fn init() -> Result<(), SetLoggerError>
Sets a LogTracer
as the global logger for the log
crate.
Setting a global logger can only be done once.
use tracing_log::LogTracer;
use log;
LogTracer::init()?;
// will be available for Subscribers as a tracing Event
log::trace!("an example trace log");
This will forward all logs to tracing
and lets the current Subscriber
determine if they are enabled.
The builder
function can be used to customize the LogTracer
before
initializing it.
If you know in advance you want to filter some log levels,
use builder
or init_with_filter
instead.