Struct tracing_log::LogTracer

source ·
pub struct LogTracer { /* private fields */ }
Expand description

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

Implementations§

source§

impl LogTracer

source

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

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

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.

source

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.

Trait Implementations§

source§

impl Debug for LogTracer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for LogTracer

source§

fn default() -> Self

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

impl Log for LogTracer

source§

fn enabled(&self, metadata: &Metadata<'_>) -> bool

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

fn log(&self, record: &Record<'_>)

Logs the Record. Read more
source§

fn flush(&self)

Flushes any buffered records.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.