<!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="A type that can create `io::Write` instances."><title>MakeWriter in tracing_subscriber::fmt::writer - Rust</title><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><linkrel="stylesheet"href="../../../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../../../static.files/rustdoc-ac92e1bbe349e143.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.76.0 (07dca489a 2024-02-04)"data-channel="1.76.0"data-search-js="search-2b6ce74ff89ae146.js"data-settings-js="settings-4313503d2e1961c2.js"><scriptsrc="../../../static.files/storage-f2adc0d6ca4d09fb.js"></script><scriptdefersrc="sidebar-items.js"></script><scriptdefersrc="../../../static.files/main-305769736d49e732.js"></script><noscript><linkrel="stylesheet"href="../../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><linkrel="alternate icon"type="image/png"href="../../../static.files/favicon-16x16-8b506e7a72182f1c.png"><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 trait"><!--[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">☰</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><h2class="location"><ahref="#">MakeWriter</a></h2><divclass="sidebar-elems"><section><h3><ahref="#required-associated-types">Required Associated Types</a></h3><ulclass="block"><li><ahref="#associatedtype.Writer">Writer</a></li></ul><h3><ahref="#required-methods">Required Methods</a></h3><ulclass="block"><li><ahref="#tymethod.make_writer">make_writer</a></li></ul><h3><ahref="#provided-methods">Provided Methods</a></h3><ulclass="block"><li><ahref="#method.make_writer_for">make_writer_for</a></li></ul><h3><ahref="#foreign-impls">Implementations on Foreign Types</a></h3><ulclass="block"><li><ahref="#impl-MakeWriter%3C'a%3E-for-Arc%3CW%3E">Arc<W></a></li><li><ahref="#impl-MakeWriter%3C'a%3E-for-File">File</a></li><li><ahref="#impl-MakeWriter%3C'a%3E-for-Mutex%3CW%3E">Mutex<W></a></li></ul><h3><ahref="#implementors">Implementors</a></h3></section><h2><ahref="index.html">In tracing_subscriber::fmt::writer</a></h2></div></nav><divclass="sidebar-resizer"></div>
<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">fmt</a>::<wbr><ahref="index.html">writer</a>::<wbr><aclass="trait"href="#">MakeWriter</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/fmt/writer.rs.html#95-209">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><preclass="rust item-decl"><code>pub trait MakeWriter<'a> {
type <ahref="#associatedtype.Writer"class="associatedtype">Writer</a>: <aclass="trait"href="https://doc.rust-lang.org/1.76.0/std/io/trait.Write.html"title="trait std::io::Write">Write</a>;
}</code></pre><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>A type that can create <ahref="https://doc.rust-lang.org/1.76.0/std/io/trait.Write.html"title="trait std::io::Write"><code>io::Write</code></a> instances.</p>
<p><code>MakeWriter</code> is used by <ahref="../struct.Layer.html"title="struct tracing_subscriber::fmt::Layer"><code>fmt::Layer</code></a> or <ahref="../struct.Subscriber.html"title="struct tracing_subscriber::fmt::Subscriber"><code>fmt::Subscriber</code></a> to print
formatted text representations of <ahref="../../../tracing_core/event/struct.Event.html"title="struct tracing_core::event::Event"><code>Event</code></a>s.</p>
<p>This trait is already implemented for function pointers and
immutably-borrowing closures that return an instance of <ahref="https://doc.rust-lang.org/1.76.0/std/io/trait.Write.html"title="trait std::io::Write"><code>io::Write</code></a>, such
as <ahref="https://doc.rust-lang.org/1.76.0/std/io/stdio/fn.stdout.html"title="fn std::io::stdio::stdout"><code>io::stdout</code></a> and <ahref="https://doc.rust-lang.org/1.76.0/std/io/stdio/fn.stderr.html"title="fn std::io::stdio::stderr"><code>io::stderr</code></a>. Additionally, it is implemented for
<ahref="https://doc.rust-lang.org/1.76.0/std/sync/mutex/struct.Mutex.html"title="struct std::sync::mutex::Mutex"><code>std::sync::Mutex</code></a> when the type inside the mutex implements
<p>A single instance of a type implementing <ahref="https://doc.rust-lang.org/1.76.0/std/io/trait.Write.html"title="trait std::io::Write"><code>io::Write</code></a> may be used as a
<code>MakeWriter</code> by wrapping it in a <ahref="https://doc.rust-lang.org/1.76.0/std/sync/mutex/struct.Mutex.html"title="struct std::sync::mutex::Mutex"><code>Mutex</code></a>. For example, we could
</div></details><h2id="required-associated-types"class="section-header">Required Associated Types<ahref="#required-associated-types"class="anchor">§</a></h2><divclass="methods"><detailsclass="toggle"open><summary><sectionid="associatedtype.Writer"class="method"><aclass="src rightside"href="../../../src/tracing_subscriber/fmt/writer.rs.html#100">source</a><h4class="code-header">type <ahref="#associatedtype.Writer"class="associatedtype">Writer</a>: <aclass="trait"href="https://doc.rust-lang.org/1.76.0/std/io/trait.Write.html"title="trait std::io::Write">Write</a></h4></section></summary><divclass="docblock"><p>The concrete <ahref="https://doc.rust-lang.org/1.76.0/std/io/trait.Write.html"title="trait std::io::Write"><code>io::Write</code></a> implementation returned by <ahref="../trait.MakeWriter.html#tymethod.make_writer"title="method tracing_subscriber::fmt::MakeWriter::make_writer"><code>make_writer</code></a>.</p>
</div></details></div><h2id="required-methods"class="section-header">Required Methods<ahref="#required-methods"class="anchor">§</a></h2><divclass="methods"><detailsclass="toggle method-toggle"open><summary><sectionid="tymethod.make_writer"class="method"><aclass="src rightside"href="../../../src/tracing_subscriber/fmt/writer.rs.html#115">source</a><h4class="code-header">fn <ahref="#tymethod.make_writer"class="fn">make_writer</a>(&'a self) -> Self::<aclass="associatedtype"href="../trait.MakeWriter.html#associatedtype.Writer"title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a></h4></section></summary><divclass="docblock"><p>Returns an instance of <ahref="../trait.MakeWriter.html#associatedtype.Writer"title="associated type tracing_subscriber::fmt::MakeWriter::Writer"><code>Writer</code></a>.</p>
<p><ahref="../struct.Layer.html"title="struct tracing_subscriber::fmt::Layer"><code>fmt::Layer</code></a> or <ahref="../struct.Subscriber.html"title="struct tracing_subscriber::fmt::Subscriber"><code>fmt::Subscriber</code></a> will call this method each time an event is recorded. Ensure any state
that must be saved across writes is not lost when the <ahref="../trait.MakeWriter.html#associatedtype.Writer"title="associated type tracing_subscriber::fmt::MakeWriter::Writer"><code>Writer</code></a> instance is dropped. If
creating a <ahref="https://doc.rust-lang.org/1.76.0/std/io/trait.Write.html"title="trait std::io::Write"><code>io::Write</code></a> instance is expensive, be sure to cache it when implementing
<ahref="../trait.MakeWriter.html"title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> to improve performance.</p>
</div></details></div><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.make_writer_for"class="method"><aclass="src rightside"href="../../../src/tracing_subscriber/fmt/writer.rs.html#205-208">source</a><h4class="code-header">fn <ahref="#method.make_writer_for"class="fn">make_writer_for</a>(&'a self, meta: &<aclass="struct"href="../../../tracing_core/metadata/struct.Metadata.html"title="struct tracing_core::metadata::Metadata">Metadata</a><'_>) -> Self::<aclass="associatedtype"href="../trait.MakeWriter.html#associatedtype.Writer"title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a></h4></section></summary><divclass="docblock"><p>Returns a <ahref="../trait.MakeWriter.html#associatedtype.Writer"title="associated type tracing_subscriber::fmt::MakeWriter::Writer"><code>Writer</code></a> for writing data from the span or event described
by the provided <ahref="../../../tracing_core/metadata/struct.Metadata.html"title="struct tracing_core::metadata::Metadata"><code>Metadata</code></a>.</p>
<p>By default, this calls <ahref="../trait.MakeWriter.html#tymethod.make_writer"title="method tracing_subscriber::fmt::MakeWriter::make_writer"><code>self.make_writer()</code></a>, ignoring
the provided metadata, but implementations can override this to provide
metadata-specific behaviors.</p>
<p>This method allows <code>MakeWriter</code> implementations to implement different
behaviors based on the span or event being written. The <code>MakeWriter</code>
type might return different writers based on the provided metadata, or
might write some values to the writer before or after providing it to
the caller.</p>
<p>For example, we might want to write data from spans and events at the
<ahref="../../../tracing_core/metadata/struct.Level.html#associatedconstant.ERROR"title="associated constant tracing_core::metadata::Level::ERROR"><code>ERROR</code></a> and <ahref="../../../tracing_core/metadata/struct.Level.html#associatedconstant.WARN"title="associated constant tracing_core::metadata::Level::WARN"><code>WARN</code></a> levels to <code>stderr</code>, and data from spans or events