🛈 Note: This is pre-release documentation for the upcoming tracing 0.2.0 ecosystem.

For the release documentation, please see docs.rs, instead.

Crate tracing_log

source ·
Expand description

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


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:

Compiler support: requires rustc 1.56+


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;


// 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

Enabling the “log” and “log-always” feature flags on the tracing crate will cause all tracing spans and events to emit log::Records as they occur.

Caution: Mixing both conversions

Note that logger implementations that convert log records to trace events should not be used with Collectors that convert trace events back into log records, as doing so will result in the event recursing between the collector 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 subscriber of filtering will be required to avoid infinitely converting between Event and log::Record.

Feature Flags

  • log-tracer: enables the LogTracer type (on by default)
  • env_logger: enables the env_logger module, with helpers for working with the env_logger crate.

Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported version is 1.56. The current Tracing version is not guaranteed to build on Rust versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio project. The current stable Rust compiler and the three most recent minor versions before it will always be supported. For example, if the current stable compiler version is 1.69, the minimum supported version will not be increased past 1.66, three minor versions prior. Increasing the minimum supported compiler version is not considered a semver breaking change as long as doing so complies with this policy.



  • env_loggerenv_logger
    Utilities for configuring the env_logger crate to emit tracing events.
  • log_tracerlog-tracer
    An adapter for converting log records into tracing Events.


  • LogTracerlog-tracer
    A simple “logger” that converts all log records into tracing Events.


  • Trait implemented for tracing types that can be converted to a log equivalent.
  • Trait implemented for log types that can be converted to a tracing equivalent.
  • Extends log Events to provide complete Metadata.


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