<main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><divid="sidebar-button"tabindex="-1"><ahref="../../tracing_subscriber/all.html"title="show sidebar"></a></div><inputclass="search-input"name="search"aria-label="Run search in the documentation"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><divid="help-button"tabindex="-1"><ahref="../../help.html"title="help">?</a></div><divid="settings-menu"tabindex="-1"><ahref="../../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><sectionid="main-content"class="content"><divclass="main-heading"><h1>Trait <ahref="../index.html">tracing_subscriber</a>::<wbr><ahref="index.html">util</a>::<wbr><aclass="trait"href="#">SubscriberInitExt</a><buttonid="copy-path"title="Copy item path to clipboard"><imgsrc="../../static.files/clipboard-7571035ce49a181d.svg"width="19"height="18"alt="Copy item path"></button></h1><spanclass="out-of-band"><aclass="src"href="../../src/tracing_subscriber/util.rs.html#23-93">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><preclass="rust item-decl"><code>pub trait SubscriberInitExt<divclass="where">where
}</code></pre><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>Extension trait adding utility methods for subscriber initialization.</p>
<p>This trait provides extension methods to make configuring and setting a
<ahref="https://docs.rs/tracing/0.1.21/tracing/dispatcher/index.html#setting-the-default-subscriber">default subscriber</a> more ergonomic. It is automatically implemented for all
types that can be converted into a <ahref="https://docs.rs/tracing/0.1.21/tracing/dispatcher/index.html">trace dispatcher</a>. Since <code>Dispatch</code>
implements <code>From<T></code> for all <code>T: Subscriber</code>, all <code>Subscriber</code>
implementations will implement this extension trait as well. Types which
can be converted into <code>Subscriber</code>s, such as builders that construct a
<code>Subscriber</code>, may implement <code>Into<Dispatch></code>, and will also receive an
implementation of this trait.</p>
</div></details><h2id="provided-methods"class="section-header">Provided Methods<ahref="#provided-methods"class="anchor">§</a></h2><divclass="methods"><detailsclass="toggle method-toggle"open><summary><sectionid="method.set_default"class="method"><aclass="src rightside"href="../../src/tracing_subscriber/util.rs.html#38-43">source</a><h4class="code-header">fn <ahref="#method.set_default"class="fn">set_default</a>(self) -><aclass="struct"href="../../tracing_core/dispatcher/struct.DefaultGuard.html"title="struct tracing_core::dispatcher::DefaultGuard">DefaultGuard</a></h4></section></summary><divclass="docblock"><p>Sets <code>self</code> as the <ahref="https://docs.rs/tracing/0.1.21/tracing/dispatcher/index.html#setting-the-default-subscriber">default subscriber</a> in the current scope, returning a
guard that will unset it when dropped.</p>
<p>If the “tracing-log” feature flag is enabled, this will also initialize
a <ahref="https://crates.io/log"><code>log</code></a> compatibility layer. This allows the subscriber to consume
<code>log::Record</code>s as though they were <code>tracing</code><code>Event</code>s.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.try_init"class="method"><aclass="src rightside"href="../../src/tracing_subscriber/util.rs.html#58-74">source</a><h4class="code-header">fn <ahref="#method.try_init"class="fn">try_init</a>(self) -><aclass="enum"href="https://doc.rust-lang.org/1.77.1/core/result/enum.Result.html"title="enum core::result::Result">Result</a><<aclass="primitive"href="https://doc.rust-lang.org/1.77.1/std/primitive.unit.html">()</a>, <aclass="struct"href="struct.TryInitError.html"title="struct tracing_subscriber::util::TryInitError">TryInitError</a>></h4></section></summary><divclass="docblock"><p>Attempts to set <code>self</code> as the <ahref="https://docs.rs/tracing/0.1.21/tracing/dispatcher/index.html#setting-the-default-subscriber">global default subscriber</a> in the current
scope, returning an error if one is already set.</p>
<p>If the “tracing-log” feature flag is enabled, this will also attempt to
initialize a <ahref="https://crates.io/log"><code>log</code></a> compatibility layer. This allows the subscriber to
consume <code>log::Record</code>s as though they were <code>tracing</code><code>Event</code>s.</p>
<p>This method returns an error if a global default subscriber has already
been set, or if a <code>log</code> logger has already been set (when the
“tracing-log” feature is enabled).</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.init"class="method"><aclass="src rightside"href="../../src/tracing_subscriber/util.rs.html#89-92">source</a><h4class="code-header">fn <ahref="#method.init"class="fn">init</a>(self)</h4></section></summary><divclass="docblock"><p>Attempts to set <code>self</code> as the <ahref="https://docs.rs/tracing/0.1.21/tracing/dispatcher/index.html#setting-the-default-subscriber">global default subscriber</a> in the current
scope, panicking if this fails.</p>
<p>If the “tracing-log” feature flag is enabled, this will also attempt to
initialize a <ahref="https://crates.io/log"><code>log</code></a> compatibility layer. This allows the subscriber to
consume <code>log::Record</code>s as though they were <code>tracing</code><code>Event</code>s.</p>
<p>This method panics if a global default subscriber has already been set,
or if a <code>log</code> logger has already been set (when the “tracing-log”
</div></details></div><h2id="object-safety"class="section-header">Object Safety<ahref="#object-safety"class="anchor">§</a></h2><divclass="object-safety-info">This trait is <b>not</b><ahref="https://doc.rust-lang.org/1.77.1/reference/items/traits.html#object-safety">object safe</a>.</div><h2id="implementors"class="section-header">Implementors<ahref="#implementors"class="anchor">§</a></h2><divid="implementors-list"><sectionid="impl-SubscriberInitExt-for-T"class="impl"><aclass="src rightside"href="../../src/tracing_subscriber/util.rs.html#95">source</a><ahref="#impl-SubscriberInitExt-for-T"class="anchor">§</a><h3class="code-header">impl<T><aclass="trait"href="trait.SubscriberInitExt.html"title="trait tracing_subscriber::util::SubscriberInitExt">SubscriberInitExt</a> for T<divclass="where">where