logo
pub struct LogTracer { /* private fields */ }
Expand description

A simple “logger” that converts all log records into tracing Events.

Implementations

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");

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");

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.

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

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Determines if a log message with the specified metadata would be logged. Read more

Logs the Record. Read more

Flushes any buffered records.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.