pub struct LogTracer { /* private fields */ }
log-tracer
only.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>
Available on crate feature std
only.
pub fn init_with_filter(level: LevelFilter) -> Result<(), SetLoggerError>
std
only.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>
Available on crate feature std
only.
pub fn init() -> Result<(), SetLoggerError>
std
only.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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LogTracer
impl RefUnwindSafe for LogTracer
impl Send for LogTracer
impl Sync for LogTracer
impl Unpin for LogTracer
impl UnwindSafe for LogTracer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 16 bytes