Struct tracing_log::LogTracer[][src]

pub struct LogTracer { /* fields omitted */ }

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

Implementations

impl LogTracer[src]

pub fn builder() -> Builder[src]

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

pub fn new() -> Self[src]

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

pub fn init_with_filter(level: LevelFilter) -> Result<(), SetLoggerError>[src]

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.

pub fn init() -> Result<(), SetLoggerError>[src]

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

impl Debug for LogTracer[src]

impl Default for LogTracer[src]

impl Log for LogTracer[src]

Auto Trait Implementations

impl RefUnwindSafe for LogTracer

impl Send for LogTracer

impl Sync for LogTracer

impl Unpin for LogTracer

impl UnwindSafe for LogTracer

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.