tracing_log

Struct 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. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.