<!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="Utilities for implementing and composing `tracing` subscribers."><title>tracing_subscriber - 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_subscriber"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_subscriber/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_subscriber/index.html"><imgsrc="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png"alt="logo"></a><h2><ahref="../tracing_subscriber/index.html">tracing_subscriber</a><spanclass="version">0.3.18</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="#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_subscriber</a><buttonid="copy-path"title="Copy item path to clipboard">Copy item path</button></h1><spanclass="out-of-band"><aclass="src"href="../src/tracing_subscriber/lib.rs.html#1-250">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>Utilities for implementing and composing <ahref="https://docs.rs/tracing/latest/tracing"><code>tracing</code></a> subscribers.</p>
<p><ahref="https://docs.rs/tracing/latest/tracing"><code>tracing</code></a> is a framework for instrumenting Rust programs to collect
scoped, structured, and async-aware diagnostics. The <ahref="../tracing_core/subscriber/trait.Subscriber.html"title="trait tracing_core::subscriber::Subscriber"><code>Subscriber</code></a> trait
represents the functionality necessary to collect this trace data. This
crate contains tools for composing subscribers out of smaller units of
behaviour, and batteries-included implementations of common subscriber
functionality.</p>
<p><code>tracing-subscriber</code> is intended for use by both <code>Subscriber</code> authors and
application authors using <code>tracing</code> to instrument their applications.</p>
<p>The most important component of the <code>tracing-subscriber</code> API is the
<ahref="layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer"><code>Layer</code></a> trait, which provides a composable abstraction for building
<ahref="../tracing_core/subscriber/trait.Subscriber.html"title="trait tracing_core::subscriber::Subscriber"><code>Subscriber</code></a>s. Like the <ahref="../tracing_core/subscriber/trait.Subscriber.html"title="trait tracing_core::subscriber::Subscriber"><code>Subscriber</code></a> trait, a <ahref="layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer"><code>Layer</code></a> defines a
particular behavior for collecting trace data. Unlike <ahref="../tracing_core/subscriber/trait.Subscriber.html"title="trait tracing_core::subscriber::Subscriber"><code>Subscriber</code></a>s,
which implement a <em>complete</em> strategy for how trace data is collected,
<ahref="layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer"><code>Layer</code></a>s provide <em>modular</em> implementations of specific behaviors.
Therefore, they can be <ahref="layer/index.html#composing-layers"title="mod tracing_subscriber::layer">composed together</a> to form a <ahref="../tracing_core/subscriber/trait.Subscriber.html"title="trait tracing_core::subscriber::Subscriber"><code>Subscriber</code></a> which is
capable of recording traces in a variety of ways. See the <ahref="layer/index.html"title="mod tracing_subscriber::layer"><code>layer</code> module’s
documentation</a> for details on using <ahref="layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer"><code>Layer</code></a>s.</p>
<p>In addition, the <ahref="layer/trait.Filter.html"title="trait tracing_subscriber::layer::Filter"><code>Filter</code></a> trait defines an interface for filtering what
spans and events are recorded by a particular layer. This allows different
<ahref="layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer"><code>Layer</code></a>s to handle separate subsets of the trace data emitted by a
program. See the <ahref="layer/index.html#per-layer-filtering"title="mod tracing_subscriber::layer">documentation on per-layer filtering</a> for more
information on using <ahref="layer/trait.Filter.html"title="trait tracing_subscriber::layer::Filter"><code>Filter</code></a>s.</p>
<p>The following <code>Subscriber</code>s are provided for application authors:</p>
<ul>
<li><ahref="fmt/index.html"title="mod tracing_subscriber::fmt"><code>fmt</code></a> - Formats and logs tracing data (requires the <code>fmt</code> feature flag)</li>
<li><code>std</code>: Enables APIs that depend on the Rust standard library
(enabled by default).</li>
<li><code>alloc</code>: Depend on <ahref="https://doc.rust-lang.org/alloc/index.html"><code>liballoc</code></a> (enabled by “std”).</li>
<li><code>env-filter</code>: Enables the <ahref="filter/struct.EnvFilter.html"title="struct tracing_subscriber::filter::EnvFilter"><code>EnvFilter</code></a> type, which implements filtering
similar to the <ahref="https://crates.io/crates/env_logger"><code>env_logger</code> crate</a>. <strong>Requires “std”</strong>.</li>
<li><code>fmt</code>: Enables the <ahref="fmt/index.html"title="mod tracing_subscriber::fmt"><code>fmt</code></a> module, which provides a subscriber
implementation for printing formatted representations of trace events.
Enabled by default. <strong>Requires “registry” and “std”</strong>.</li>
<li><code>ansi</code>: Enables <code>fmt</code> support for ANSI terminal colors. Enabled by
default.</li>
<li><code>registry</code>: enables the <ahref="registry/index.html"title="mod tracing_subscriber::registry"><code>registry</code></a> module. Enabled by default.
<strong>Requires “std”</strong>.</li>
<li><code>json</code>: Enables <code>fmt</code> support for JSON output. In JSON output, the ANSI
feature does nothing. <strong>Requires “fmt” and “std”</strong>.</li>
<li><code>local-time</code>: Enables local time formatting when using the <ahref="https://crates.io/crates/time"><code>time</code>
crate</a>’s timestamp formatters with the <code>fmt</code> subscriber.</li>
<li><ahref="https://crates.io/crates/tracing-log"><code>tracing-log</code></a>: Enables better formatting for events emitted by <code>log</code>
macros in the <code>fmt</code> subscriber. Enabled by default.</li>
<li><ahref="https://crates.io/crates/time"><code>time</code></a>: Enables support for using the <ahref="https://crates.io/crates/time"><code>time</code> crate</a> for timestamp
formatting in the <code>fmt</code> subscriber.</li>
<li><ahref="https://crates.io/crates/smallvec"><code>smallvec</code></a>: Causes the <code>EnvFilter</code> type to use the <code>smallvec</code> crate (rather
than <code>Vec</code>) as a performance optimization. Enabled by default.</li>
<li><ahref="https://crates.io/crates/parking_lot"><code>parking_lot</code></a>: Use the <code>parking_lot</code> crate’s <code>RwLock</code> implementation
rather than the Rust standard library’s implementation.</li>
<p>In embedded systems and other bare-metal applications, <code>tracing</code> can be
used without requiring the Rust standard library, although some features are
disabled. Although most of the APIs provided by <code>tracing-subscriber</code>, such
as <ahref="fmt/index.html"title="mod tracing_subscriber::fmt"><code>fmt</code></a> and <ahref="filter/struct.EnvFilter.html"title="struct tracing_subscriber::filter::EnvFilter"><code>EnvFilter</code></a>, require the standard library, some
functionality, such as the <ahref="layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer"><code>Layer</code></a> trait, can still be used in
<code>no_std</code> environments.</p>
<p>The dependency on the standard library is controlled by two crate feature
flags, “std”, which enables the dependency on <ahref="https://doc.rust-lang.org/std/index.html"><code>libstd</code></a>, and “alloc”, which
enables the dependency on <ahref="https://doc.rust-lang.org/alloc/index.html"><code>liballoc</code></a> (and is enabled by the “std”
feature). These features are enabled by default, but <code>no_std</code> users can
<p>These feature flags enable <strong>unstable</strong> features. The public API may break in 0.1.x
releases. To enable these features, the <code>--cfg tracing_unstable</code> must be passed to
<code>rustc</code> when compiling.</p>
<p>The following unstable feature flags are currently available:</p>
<ul>
<li><code>valuable</code>: Enables support for serializing values recorded using the
<ahref="https://crates.io/crates/valuable"><code>valuable</code></a> crate as structured JSON in the <ahref="crate::fmt::format::Json"><code>format::Json</code></a> formatter.</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.fmt"><code>pub use fmt::<aclass="fn"href="fmt/fn.fmt.html"title="fn tracing_subscriber::fmt::fmt">fmt</a>;</code></div></li><li><divclass="item-name"id="reexport.FmtSubscriber"><code>pub use fmt::<aclass="struct"href="fmt/struct.Subscriber.html"title="struct tracing_subscriber::fmt::Subscriber">Subscriber</a> as FmtSubscriber;</code></div></li><li><divclass="item-name"id="reexport.EnvFilter"><code>pub use filter::<aclass="struct"href="filter/struct.EnvFilter.html"title="struct tracing_subscriber::filter::EnvFilter">EnvFilter</a>;</code></div></li><li><divclass="item-name"id="reexport.Layer"><code>pub use layer::<aclass="trait"href="layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer">Layer</a>;</code></div></li><li><divclass="item-name"id="reexport.Registry"><code>pub use registry::<aclass="struct"href="registry/struct.Registry.html"title="struct tracing_subscriber::registry::Registry">Registry</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="field/index.html"title="mod tracing_subscriber::field">field</a></div><divclass="desc docblock-short">Utilities for working with <ahref="../tracing_core/field/index.html"title="mod tracing_core::field">fields</a> and <ahref="field/trait.Visit.html"title="trait tracing_subscriber::field::Visit">field visitors</a>.</div></li><li><divclass="item-name"><aclass="mod"href="filter/index.html"title="mod tracing_subscriber::filter">filter</a></div><divclass="desc docblock-short"><ahref="layer/index.html"title="mod tracing_subscriber::layer"><code>Layer</code></a>s that control which spans and events are enabled by the wrapped
subscriber.</div></li><li><divclass="item-name"><aclass="mod"href="fmt/index.html"title="mod tracing_subscriber::fmt">fmt</a></div><divclass="desc docblock-short">A <code>Subscriber</code> for formatting and logging <code>tracing</code> data.</div></li><li><divclass="item-name"><aclass="mod"href="layer/index.html"title="mod tracing_subscriber::layer">layer</a></div><divclass="desc docblock-short">The <ahref="layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer"><code>Layer</code></a> trait, a composable abstraction for building <ahref="../tracing_core/subscriber/trait.Subscriber.html"title="trait tracing_core::subscriber::Subscriber"><code>Subscriber</code></a>s.</div></li><li><divclass="item-name"><aclass="mod"href="prelude/index.html"title="mod tracing_subscriber::prelude">prelude</a></div><divclass="desc docblock-short">The <code>tracing-subscriber</code> prelude.</div></li><li><divclass="item-name"><aclass="mod"href="registry/index.html"title="mod tracing_subscriber::registry">registry</a></div><divclass="desc docblock-short">Storage for span data shared by multiple <ahref="layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer"><code>Layer</code></a>s.</div></li><li><divclass="item-name"><aclass="mod"href="reload/index.html"title="mod tracing_subscriber::reload">reload</a></div><divclass="desc docblock-short">Wrapper for a <code>Layer</code> to allow it to be dynamically reloaded.</div></li><li><divclass="item-name"><aclass="mod"href="util/index.html"title="mod tracing_subscriber::util">util</a></div><divclass="desc docblock-short">Extension traits and other utilities to make working with subscribers more