[][src]Crate tracing_log

Adapters for connecting unstructured log records from the log crate into the tracing ecosystem.

Overview

tracing is a framework for instrumenting Rust programs with context-aware, structured, event-based diagnostic information. This crate provides compatibility layers for using tracing alongside the logging facade provided by the log crate.

This crate provides:

Usage

Convert log records to tracing Events

To convert log::Records as tracing::Events, set LogTracer as the default logger by calling its init or init_with_filter methods.

use tracing_log::LogTracer;
use log;

LogTracer::init()?;

// will be available for Subscribers as a tracing Event
log::trace!("an example trace log");

This conversion does not convert unstructured data in log records (such as values passed as format arguments to the log! macro) to structured tracing fields. However, it does attach these new events to to the span that was currently executing when the record was logged. This is the primary use-case for this library: making it possible to locate the log records emitted by dependencies which use log within the context of a trace.

Convert tracing Events to logs

This conversion can be done with TraceLogger, a Subscriber which records tracing spans and events and outputs log records.

Caution: Mixing both conversions

Note that logger implementations that convert log records to trace events should not be used with Subscribers that convert trace events back into log records (such as the TraceLogger), as doing so will result in the event recursing between the subscriber and the logger forever (or, in real life, probably overflowing the call stack).

If the logging of trace events generated from log records produced by the log crate is desired, either the log crate should not be used to implement this logging, or an additional layer of filtering will be required to avoid infinitely converting between Event and log::Record.

Modules

log_tracer
trace_logger

Structs

LogTracer

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

TraceLogger

A tracing_core::Subscriber implementation that logs all recorded trace events.

Traits

AsLog
AsTrace
NormalizeEvent

Extends log Events to provide complete Metadata.

Functions

format_trace

Format a log record as a trace event in the current span.