<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 an
implementation of the <ahref="https://docs.rs/tracing/latest/tracing/trait.Subscriber.html"><code>Subscriber</code></a> trait that records <code>tracing</code>’s <code>Event</code>s
and <code>Span</code>s by formatting them as text and logging them to stdout.</p>
<h3id="filtering-events-with-environment-variables"><aclass="doc-anchor"href="#filtering-events-with-environment-variables">§</a>Filtering Events with Environment Variables</h3>
<p>The default subscriber installed by <code>init</code> enables you to filter events
at runtime using environment variables (using the <ahref="../filter/struct.EnvFilter.html"title="struct tracing_subscriber::filter::EnvFilter"><code>EnvFilter</code></a>).</p>
<p>The filter syntax is a superset of the <ahref="https://docs.rs/env_logger/"><code>env_logger</code></a> syntax.</p>
<p>For example:</p>
<ul>
<li>Setting <code>RUST_LOG=debug</code> enables all <code>Span</code>s and <code>Event</code>s
set to the log level <code>DEBUG</code> or higher</li>
<li>Setting <code>RUST_LOG=my_crate=trace</code> enables <code>Span</code>s and <code>Event</code>s
in <code>my_crate</code> at all log levels</li>
</ul>
<p><strong>Note</strong>: This should <strong>not</strong> be called by libraries. Libraries should use
<ahref="https://crates.io/crates/tracing"><code>tracing</code></a> to publish <code>tracing</code><code>Event</code>s.</p>
<p>The <ahref="struct.Subscriber.html"title="struct tracing_subscriber::fmt::Subscriber"><code>FmtSubscriber</code></a> formats and records <code>tracing</code> events as line-oriented logs.
<p>You can find the configuration methods for <ahref="struct.Subscriber.html"title="struct tracing_subscriber::fmt::Subscriber"><code>FmtSubscriber</code></a> in
<p>The output format used by the layer and subscriber in this module is
represented by implementing the <ahref="trait.FormatEvent.html"title="trait tracing_subscriber::fmt::FormatEvent"><code>FormatEvent</code></a> trait, and can be
customized. This module provides a number of formatter implementations:</p>
<ul>
<li>
<p><ahref="format/struct.Full.html"title="struct tracing_subscriber::fmt::format::Full"><code>format::Full</code></a>: The default formatter. This emits human-readable,
single-line logs for each event that occurs, with the current span context
displayed before the formatted representation of the event. See
<ahref="format/struct.Full.html#example-output"title="struct tracing_subscriber::fmt::format::Full">here</a> for sample output.</p>
</li>
<li>
<p><ahref="format/struct.Compact.html"title="struct tracing_subscriber::fmt::format::Compact"><code>format::Compact</code></a>: A variant of the default formatter, optimized for
short line lengths. Fields from the current span context are appended to
the fields of the formatted event. See
<ahref="format/struct.Compact.html#example-output"title="struct tracing_subscriber::fmt::format::Compact">here</a> for sample output.</p>
<p>The formatting of log lines for spans and events is controlled by two
traits, <ahref="trait.FormatEvent.html"title="trait tracing_subscriber::fmt::FormatEvent"><code>FormatEvent</code></a> and <ahref="trait.FormatFields.html"title="trait tracing_subscriber::fmt::FormatFields"><code>FormatFields</code></a>. The <ahref="trait.FormatEvent.html"title="trait tracing_subscriber::fmt::FormatEvent"><code>FormatEvent</code></a> trait
determines the overall formatting of the log line, such as what information
from the event’s metadata and span context is included and in what order.
The <ahref="trait.FormatFields.html"title="trait tracing_subscriber::fmt::FormatFields"><code>FormatFields</code></a> trait determines how fields — both the event’s
fields and fields on spans — are formatted.</p>
<p>The <ahref="format/index.html"title="mod tracing_subscriber::fmt::format"><code>fmt::format</code></a> module provides several types which implement these traits,
many of which expose additional configuration options to customize their
output. The <ahref="format/struct.Format.html"title="struct tracing_subscriber::fmt::format::Format"><code>format::Format</code></a> type implements common configuration used by
all the formatters provided in this crate, and can be used as a builder to
set specific formatting settings. For example:</p>
.with_level(<spanclass="bool-val">false</span>) <spanclass="comment">// don't include levels in formatted output
</span>.with_target(<spanclass="bool-val">false</span>) <spanclass="comment">// don't include targets
</span>.with_thread_ids(<spanclass="bool-val">true</span>) <spanclass="comment">// include the thread ID of the current thread
</span>.with_thread_names(<spanclass="bool-val">true</span>) <spanclass="comment">// include the name of the current thread
</span>.compact(); <spanclass="comment">// use the `Compact` formatting style.
// Create a `fmt` subscriber that uses our custom event format, and set it
// as the default.
</span>tracing_subscriber::fmt()
.event_format(format)
.init();</code></pre></div>
<p>However, if a specific output format is needed, other crates can
also implement <ahref="trait.FormatEvent.html"title="trait tracing_subscriber::fmt::FormatEvent"><code>FormatEvent</code></a> and <ahref="trait.FormatFields.html"title="trait tracing_subscriber::fmt::FormatFields"><code>FormatFields</code></a>. See those traits’
documentation for details on how to implement them.</p>
<p>If you want to filter the <code>tracing</code><code>Events</code> based on environment
variables, you can use the <ahref="../filter/struct.EnvFilter.html"title="struct tracing_subscriber::filter::EnvFilter"><code>EnvFilter</code></a> as follows:</p>
<p>As mentioned above, the <ahref="../filter/struct.EnvFilter.html"title="struct tracing_subscriber::filter::EnvFilter"><code>EnvFilter</code></a> allows <code>Span</code>s and <code>Event</code>s to
be filtered at runtime by setting the <code>RUST_LOG</code> environment variable.</p>
<p>You can find the other available <ahref="../filter/index.html"title="mod tracing_subscriber::filter"><code>filter</code></a>s in the documentation.</p>
<p>Composing an <ahref="../filter/struct.EnvFilter.html"title="struct tracing_subscriber::filter::EnvFilter"><code>EnvFilter</code></a><code>Layer</code> and a <ahref="struct.Layer.html"title="struct tracing_subscriber::fmt::Layer">format <code>Layer</code></a>:</p>
</div></details><h2id="modules"class="section-header">Modules<ahref="#modules"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="mod"href="format/index.html"title="mod tracing_subscriber::fmt::format">format</a></div><divclass="desc docblock-short">Formatters for logging <code>tracing</code> events.</div></li><li><divclass="item-name"><aclass="mod"href="time/index.html"title="mod tracing_subscriber::fmt::time">time</a></div><divclass="desc docblock-short">Formatters for event timestamps.</div></li><li><divclass="item-name"><aclass="mod"href="writer/index.html"title="mod tracing_subscriber::fmt::writer">writer</a></div><divclass="desc docblock-short">Abstractions for creating <ahref="https://doc.rust-lang.org/1.80.0/std/io/trait.Write.html"title="trait std::io::Write"><code>io::Write</code></a> instances.</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.FmtContext.html"title="struct tracing_subscriber::fmt::FmtContext">FmtContext</a></div><divclass="desc docblock-short">Provides the current span context to a formatter.</div></li><li><divclass="item-name"><aclass="struct"href="struct.FormattedFields.html"title="struct tracing_subscriber::fmt::FormattedFields">FormattedFields</a></div><divclass="desc docblock-short">A formatted representation of a span’s fields stored in its <ahref="../registry/struct.Extensions.html"title="struct tracing_subscriber::registry::Extensions">extensions</a>.</div></li><li><divclass="item-name"><aclass="struct"href="struct.Layer.html"title="struct tracing_subscriber::fmt::Layer">Layer</a></div><divclass="desc docblock-short">A <ahref="../layer/trait.Layer.html"title="trait tracing_subscriber::layer::Layer"><code>Layer</code></a> that logs formatted representations of <code>tracing</code> events.</div></li><li><divclass="item-name"><aclass="struct"href="struct.Subscriber.html"title="struct tracing_subscriber::fmt::Subscriber">Subscriber</a></div><divclass="desc docblock-short">A <code>Subscriber</code> that logs formatted representations of <code>tracing</code> events.</div></li><li><divclass="item-name"><aclass="struct"href="struct.SubscriberBuilder.html"title="struct tracing_subscriber::fmt::SubscriberBuilder">SubscriberBuilder</a></div><divclass="desc docblock-short">Configures and constructs <code>Subscriber</code>s.</div></li><li><divclass="item-name"><aclass="struct"href="struct.TestWriter.html"title="struct tracing_subscriber::fmt::TestWriter">TestWriter</a></div><divclass="desc docblock-short">A writer intended to support <ahref="https://doc.rust-lang.org/book/ch11-02-running-tests.html#showing-function-output"><code>libtest</code>’s output capturing</a> for use in unit tests.</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.FormatEvent.html"title="trait tracing_subscriber::fmt::FormatEvent">FormatEvent</a></div><divclass="desc docblock-short">A type that can format a tracing <ahref="../../tracing_core/event/struct.Event.html"title="struct tracing_core::event::Event"><code>Event</code></a> to a <ahref="format/struct.Writer.html"title="struct tracing_subscriber::fmt::format::Writer"><code>Writer</code></a>.</div></li><li><divclass="item-name"><aclass="trait"href="trait.FormatFields.html"title="trait tracing_subscriber::fmt::FormatFields">FormatFields</a></div><divclass="desc docblock-short">A type that can format a <ahref="../field/trait.RecordFields.html"title="trait tracing_subscriber::field::RecordFields">set of fields</a> to a <ahref="format/struct.Writer.html"title="struct tracing_subscriber::fmt::format::Writer"><code>Writer</code></a>.</div></li><li><divclass="item-name"><aclass="trait"href="trait.MakeWriter.html"title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a></div><divclass="descdocblock
filters based on the value of the <ahref="../filter/struct.EnvFilter.html#associatedconstant.DEFAULT_ENV"title="associated constant tracing_subscriber::filter::EnvFilter::DEFAULT_ENV"><code>RUST_LOG</code> environment variable</a>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.layer.html"title="fn tracing_subscriber::fmt::layer">layer</a></div><divclass="desc docblock-short">Returns a new <ahref="struct.Layer.html"title="struct tracing_subscriber::fmt::Layer">formatting layer</a> that can be <ahref="../layer/index.html"title="mod tracing_subscriber::layer">composed</a> with other layers to
construct a <ahref="struct.Subscriber.html"title="struct tracing_subscriber::fmt::Subscriber"><code>Subscriber</code></a>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.time.html"title="fn tracing_subscriber::fmt::time">time</a></div><divclass="desc docblock-short">Returns a new <code>SystemTime</code> timestamp provider.</div></li><li><divclass="item-name"><aclass="fn"href="fn.try_init.html"title="fn tracing_subscriber::fmt::try_init">try_init</a></div><divclass="desc docblock-short">Install a global tracing subscriber that listens for events and
filters based on the value of the <ahref="../filter/struct.EnvFilter.html#associatedconstant.DEFAULT_ENV"title="associated constant tracing_subscriber::filter::EnvFilter::DEFAULT_ENV"><code>RUST_LOG</code> environment variable</a>,
if one is not already set.</div></li></ul><h2id="types"class="section-header">Type Aliases<ahref="#types"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="type"href="type.Formatter.html"title="type tracing_subscriber::fmt::Formatter">Formatter</a></div><divclass="desc docblock-short">A <code>Subscriber</code> that logs formatted representations of <code>tracing</code> events.