<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="Adapters for connecting unstructured log records from the `log` crate into the `tracing` ecosystem."><title>tracing_log - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><linkrel="stylesheet"href="../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../static.files/rustdoc-dd39b87e5fcfba68.css"><metaname="rustdoc-vars"data-root-path="../"data-static-root-path="../static.files/"data-current-crate="tracing_log"data-themes=""data-resource-suffix=""data-rustdoc-version="1.80.0 (051478957 2024-07-21)"data-channel="1.80.0"data-search-js="search-d52510db62a78183.js"data-settings-js="settings-4313503d2e1961c2.js"><scriptsrc="../static.files/storage-118b08c4c78b968e.js"></script><scriptdefersrc="../crates.js"></script><scriptdefersrc="../static.files/main-20a3ad099b048cf2.js"></script><noscript><linkrel="stylesheet"href="../static.files/noscript-df360f571f6edeae.css"></noscript><linkrel="alternate icon"type="image/png"href="../static.files/favicon-32x32-422f7d1d52889060.png"><linkrel="icon"type="image/svg+xml"href="../static.files/favicon-2c020d218678b618.svg"></head><bodyclass="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="mobile-topbar"><buttonclass="sidebar-menu-toggle"title="show sidebar"></button><aclass="logo-container"href="../tracing_log/index.html"><imgsrc="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png"alt=""></a></nav><navclass="sidebar"><divclass="sidebar-crate"><aclass="logo-container"href="../tracing_log/index.html"><imgsrc="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png"alt="logo"></a><h2><ahref="../tracing_log/index.html">tracing_log</a><spanclass="version">0.2.0</span></h2></div><divclass="sidebar-elems"><ulclass="block"><li><aid="all-types"href="all.html">All Items</a></li></ul><section><ulclass="block"><li><ahref="#reexports">Re-exports</a></li><li><ahref="#modules">Modules</a></li><li><ahref="#structs">Structs</a></li><li><ahref="#traits">Traits</a></li><li><ahref="#functions">Functions</a></li></ul></section></div></nav><divclass="sidebar-resizer"></div><main><divclass="width-limiter"><rustdoc-search></rustdoc-search><sectionid="main-content"class="content"><divclass="main-heading"><h1>Crate <aclass="mod"href="#">tracing_log</a><buttonid="copy-path"title="Copy item path to clipboard">Copy item path</button></h1><spanclass="out-of-band"><aclass="src"href="../src/tracing_log/lib.rs.html#1-600">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>Adapters for connecting unstructured log records from the <code>log</code> crate into
<p><ahref="https://crates.io/crates/tracing"><code>tracing</code></a> is a framework for instrumenting Rust programs with context-aware,
structured, event-based diagnostic information. This crate provides
compatibility layers for using <code>tracing</code> alongside the logging facade provided
by the <ahref="../log/index.html"title="mod log"><code>log</code></a> crate.</p>
<p>This crate provides:</p>
<ul>
<li><ahref="trait.AsTrace.html"title="trait tracing_log::AsTrace"><code>AsTrace</code></a> and <ahref="trait.AsLog.html"title="trait tracing_log::AsLog"><code>AsLog</code></a> traits for converting between <code>tracing</code> and <code>log</code> types.</li>
<li><ahref="struct.LogTracer.html"title="struct tracing_log::LogTracer"><code>LogTracer</code></a>, a <ahref="../log/trait.Log.html"title="trait log::Log"><code>log::Log</code></a> implementation that consumes <ahref="../log/struct.Record.html"title="struct log::Record"><code>log::Record</code></a>s
and outputs them as <ahref="https://docs.rs/tracing/latest/tracing/struct.Event.html"><code>tracing::Event</code></a>.</li>
<h2id="usage"><aclass="doc-anchor"href="#usage">§</a>Usage</h2><h3id="convert-log-records-to-tracing-events"><aclass="doc-anchor"href="#convert-log-records-to-tracing-events">§</a>Convert log records to tracing <code>Event</code>s</h3>
<p>To convert <ahref="../log/struct.Record.html"title="struct log::Record"><code>log::Record</code></a>s as <ahref="https://docs.rs/tracing/latest/tracing/struct.Event.html"><code>tracing::Event</code></a>s, set <code>LogTracer</code> as the default
logger by calling its <ahref="struct.LogTracer.html#method.init"title="associated function tracing_log::LogTracer::init"><code>init</code></a> or <ahref="struct.LogTracer.html#method.init_with_filter"title="associated function tracing_log::LogTracer::init_with_filter"><code>init_with_filter</code></a> methods.</p>
<h3id="convert-tracing-events-to-logs"><aclass="doc-anchor"href="#convert-tracing-events-to-logs">§</a>Convert tracing <code>Event</code>s to logs</h3>
<p>Enabling the <ahref="https://docs.rs/tracing/latest/tracing/#crate-feature-flags">“log” and “log-always” feature flags</a> on the <code>tracing</code>
crate will cause all <code>tracing</code> spans and events to emit <code>log::Record</code>s as
<li><code>std</code>: enables features that require the Rust standard library (on by default)</li>
<li><code>log-tracer</code>: enables the <code>LogTracer</code> type (on by default)</li>
<li><code>interest-cache</code>: makes it possible to configure an interest cache for
logs emitted through the <code>log</code> crate (see <ahref="log_tracer::Builder::with_interest_cache"><code>Builder::with_interest_cache</code></a>); requires <code>std</code></li>
</div></details><h2id="reexports"class="section-header">Re-exports<ahref="#reexports"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"id="reexport.log"><code>pub use <aclass="mod"href="../log/index.html"title="mod log">log</a>;</code></div></li></ul><h2id="modules"class="section-header">Modules<ahref="#modules"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="mod"href="log_tracer/index.html"title="mod tracing_log::log_tracer">log_tracer</a></div><divclass="desc docblock-short">An adapter for converting <ahref="../log/index.html"title="mod log"><code>log</code></a> records into <code>tracing</code><code>Event</code>s.</div></li></ul><h2id="structs"class="section-header">Structs<ahref="#structs"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="struct"href="struct.LogTracer.html"title="struct tracing_log::LogTracer">LogTracer</a></div><divclass="desc docblock-short">A simple “logger” that converts all log records into <code>tracing</code><code>Event</code>s.</div></li></ul><h2id="traits"class="section-header">Traits<ahref="#traits"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="trait"href="trait.AsLog.html"title="trait tracing_log::AsLog">AsLog</a></div><divclass="desc docblock-short">Trait implemented for <code>tracing</code> types that can be converted to a <code>log</code>
equivalent.</div></li><li><divclass="item-name"><aclass="trait"href="trait.AsTrace.html"title="trait tracing_log::AsTrace">AsTrace</a></div><divclass="desc docblock-short">Trait implemented for <code>log</code> types that can be converted to a <code>tracing</code>
equivalent.</div></li><li><divclass="item-name"><aclass="trait"href="trait.NormalizeEvent.html"title="trait tracing_log::NormalizeEvent">NormalizeEvent</a></div><divclass="desc docblock-short">Extends log <code>Event</code>s to provide complete <code>Metadata</code>.</div></li></ul><h2id="functions"class="section-header">Functions<ahref="#functions"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="fn"href="fn.format_trace.html"title="fn tracing_log::format_trace">format_trace</a></div><divclass="desc docblock-short">Format a log record as a trace event in the current span.</div></li></ul></section></div></main></body></html>