mirror of
https://github.com/NotAShelf/mpvrc.git
synced 2026-04-25 02:55:13 +00:00
deploy: de38ae62916547ad097c066f94a32e9ba7790eeb
This commit is contained in:
commit
9a86359447
28502 changed files with 1261284 additions and 0 deletions
45
tracing_subscriber/fmt/writer/enum.EitherWriter.html
Normal file
45
tracing_subscriber/fmt/writer/enum.EitherWriter.html
Normal file
File diff suppressed because one or more lines are too long
12
tracing_subscriber/fmt/writer/index.html
Normal file
12
tracing_subscriber/fmt/writer/index.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Abstractions for creating `io::Write` instances."><title>tracing_subscriber::fmt::writer - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-42caa33d.css"><meta name="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.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../../tracing_subscriber/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../../tracing_subscriber/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></a><h2><a href="../../../tracing_subscriber/index.html">tracing_<wbr>subscriber</a><span class="version">0.3.19</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module writer</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In tracing_<wbr>subscriber::<wbr>fmt</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">tracing_subscriber</a>::<wbr><a href="../index.html">fmt</a></span><h1>Module <span>writer</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/tracing_subscriber/fmt/writer.rs.html#1-1467">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Abstractions for creating <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a> instances.</p>
|
||||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.BoxMakeWriter.html" title="struct tracing_subscriber::fmt::writer::BoxMakeWriter">BoxMake<wbr>Writer</a></div><div class="desc docblock-short">A writer that erases the specific <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a> and <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> types being used.</div></li><li><div class="item-name"><a class="struct" href="struct.MutexGuardWriter.html" title="struct tracing_subscriber::fmt::writer::MutexGuardWriter">Mutex<wbr>Guard<wbr>Writer</a></div><div class="desc docblock-short">A type implementing <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a> for a <a href="https://doc.rust-lang.org/1.84.1/std/sync/mutex/struct.MutexGuard.html" title="struct std::sync::mutex::MutexGuard"><code>MutexGuard</code></a> where the type
|
||||
inside the <a href="https://doc.rust-lang.org/1.84.1/std/sync/mutex/struct.Mutex.html" title="struct std::sync::mutex::Mutex"><code>Mutex</code></a> implements <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.OrElse.html" title="struct tracing_subscriber::fmt::writer::OrElse">OrElse</a></div><div class="desc docblock-short">Combines a <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> that returns an <a href="type.OptionalWriter.html" title="type tracing_subscriber::fmt::writer::OptionalWriter"><code>OptionalWriter</code></a> with another
|
||||
<a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>, so that the second <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> is used when the first
|
||||
<a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> returns <a href="enum.EitherWriter.html#method.none" title="associated function tracing_subscriber::fmt::writer::EitherWriter::none"><code>OptionalWriter::none</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.Tee.html" title="struct tracing_subscriber::fmt::writer::Tee">Tee</a></div><div class="desc docblock-short">Combines two types implementing <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> (or <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>std::io::Write</code></a>) to
|
||||
produce a writer that writes to both <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>’s returned writers.</div></li><li><div class="item-name"><a class="struct" href="struct.TestWriter.html" title="struct tracing_subscriber::fmt::writer::TestWriter">Test<wbr>Writer</a></div><div class="desc docblock-short">A writer intended to support <a href="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><li><div class="item-name"><a class="struct" href="struct.WithFilter.html" title="struct tracing_subscriber::fmt::writer::WithFilter">With<wbr>Filter</a></div><div class="desc docblock-short">A <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> combinator that wraps a <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> with a predicate for
|
||||
span and event <a href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata"><code>Metadata</code></a>, so that the <a href="../trait.MakeWriter.html#method.make_writer_for" title="method tracing_subscriber::fmt::MakeWriter::make_writer_for"><code>MakeWriter::make_writer_for</code></a>
|
||||
method returns <a href="enum.EitherWriter.html#method.some" title="associated function tracing_subscriber::fmt::writer::EitherWriter::some"><code>OptionalWriter::some</code></a> when the predicate returns <code>true</code>,
|
||||
and <a href="enum.EitherWriter.html#method.none" title="associated function tracing_subscriber::fmt::writer::EitherWriter::none"><code>OptionalWriter::none</code></a> when the predicate returns <code>false</code>.</div></li><li><div class="item-name"><a class="struct" href="struct.WithMaxLevel.html" title="struct tracing_subscriber::fmt::writer::WithMaxLevel">With<wbr>MaxLevel</a></div><div class="desc docblock-short">A <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> combinator that only returns an enabled <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">writer</a> for spans
|
||||
and events with metadata at or below a specified verbosity <a href="../../../tracing_core/metadata/struct.Level.html" title="struct tracing_core::metadata::Level"><code>Level</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.WithMinLevel.html" title="struct tracing_subscriber::fmt::writer::WithMinLevel">With<wbr>MinLevel</a></div><div class="desc docblock-short">A <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> combinator that only returns an enabled <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">writer</a> for spans
|
||||
and events with metadata at or above a specified verbosity <a href="../../../tracing_core/metadata/struct.Level.html" title="struct tracing_core::metadata::Level"><code>Level</code></a>.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.EitherWriter.html" title="enum tracing_subscriber::fmt::writer::EitherWriter">Either<wbr>Writer</a></div><div class="desc docblock-short">A <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">writer</a> that is one of two types implementing <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a>.</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.MakeWriter.html" title="trait tracing_subscriber::fmt::writer::MakeWriter">Make<wbr>Writer</a></div><div class="desc docblock-short">A type that can create <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a> instances.</div></li><li><div class="item-name"><a class="trait" href="trait.MakeWriterExt.html" title="trait tracing_subscriber::fmt::writer::MakeWriterExt">Make<wbr>Writer<wbr>Ext</a></div><div class="desc docblock-short">Extension trait adding combinators for working with types implementing
|
||||
<a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>.</div></li></ul><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.OptionalWriter.html" title="type tracing_subscriber::fmt::writer::OptionalWriter">Optional<wbr>Writer</a></div><div class="desc docblock-short">A <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">writer</a> which may or may not be enabled.</div></li></ul></section></div></main></body></html>
|
||||
1
tracing_subscriber/fmt/writer/sidebar-items.js
Normal file
1
tracing_subscriber/fmt/writer/sidebar-items.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
window.SIDEBAR_ITEMS = {"enum":["EitherWriter"],"struct":["BoxMakeWriter","MutexGuardWriter","OrElse","Tee","TestWriter","WithFilter","WithMaxLevel","WithMinLevel"],"trait":["MakeWriter","MakeWriterExt"],"type":["OptionalWriter"]};
|
||||
50
tracing_subscriber/fmt/writer/struct.BoxMakeWriter.html
Normal file
50
tracing_subscriber/fmt/writer/struct.BoxMakeWriter.html
Normal file
File diff suppressed because one or more lines are too long
24
tracing_subscriber/fmt/writer/struct.MutexGuardWriter.html
Normal file
24
tracing_subscriber/fmt/writer/struct.MutexGuardWriter.html
Normal file
File diff suppressed because one or more lines are too long
59
tracing_subscriber/fmt/writer/struct.OrElse.html
Normal file
59
tracing_subscriber/fmt/writer/struct.OrElse.html
Normal file
File diff suppressed because one or more lines are too long
63
tracing_subscriber/fmt/writer/struct.Tee.html
Normal file
63
tracing_subscriber/fmt/writer/struct.Tee.html
Normal file
File diff suppressed because one or more lines are too long
43
tracing_subscriber/fmt/writer/struct.TestWriter.html
Normal file
43
tracing_subscriber/fmt/writer/struct.TestWriter.html
Normal file
File diff suppressed because one or more lines are too long
60
tracing_subscriber/fmt/writer/struct.WithFilter.html
Normal file
60
tracing_subscriber/fmt/writer/struct.WithFilter.html
Normal file
File diff suppressed because one or more lines are too long
49
tracing_subscriber/fmt/writer/struct.WithMaxLevel.html
Normal file
49
tracing_subscriber/fmt/writer/struct.WithMaxLevel.html
Normal file
File diff suppressed because one or more lines are too long
49
tracing_subscriber/fmt/writer/struct.WithMinLevel.html
Normal file
49
tracing_subscriber/fmt/writer/struct.WithMinLevel.html
Normal file
File diff suppressed because one or more lines are too long
147
tracing_subscriber/fmt/writer/trait.MakeWriter.html
Normal file
147
tracing_subscriber/fmt/writer/trait.MakeWriter.html
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A type that can create `io::Write` instances."><title>MakeWriter in tracing_subscriber::fmt::writer - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-42caa33d.css"><meta name="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.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../../tracing_subscriber/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../../tracing_subscriber/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></a><h2><a href="../../../tracing_subscriber/index.html">tracing_<wbr>subscriber</a><span class="version">0.3.19</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Make<wbr>Writer</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Writer" title="Writer">Writer</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.make_writer" title="make_writer">make_writer</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.make_writer_for" title="make_writer_for">make_writer_for</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-MakeWriter%3C'a%3E-for-Arc%3CW%3E" title="Arc<W>">Arc<W></a></li><li><a href="#impl-MakeWriter%3C'a%3E-for-File" title="File">File</a></li><li><a href="#impl-MakeWriter%3C'a%3E-for-Mutex%3CW%3E" title="Mutex<W>">Mutex<W></a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In tracing_<wbr>subscriber::<wbr>fmt::<wbr>writer</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">tracing_subscriber</a>::<wbr><a href="../index.html">fmt</a>::<wbr><a href="index.html">writer</a></span><h1>Trait <span class="trait">MakeWriter</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/tracing_subscriber/fmt/writer.rs.html#95-209">Source</a> </span></div><pre class="rust item-decl"><code>pub trait MakeWriter<'a> {
|
||||
type <a href="#associatedtype.Writer" class="associatedtype">Writer</a>: <a class="trait" href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">Write</a>;
|
||||
|
||||
// Required method
|
||||
fn <a href="#tymethod.make_writer" class="fn">make_writer</a>(&'a self) -> Self::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a>;
|
||||
|
||||
// Provided method
|
||||
fn <a href="#method.make_writer_for" class="fn">make_writer_for</a>(&'a self, meta: &<a class="struct" href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata">Metadata</a><'_>) -> Self::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a> { ... }
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A type that can create <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a> instances.</p>
|
||||
<p><code>MakeWriter</code> is used by <a href="../struct.Layer.html" title="struct tracing_subscriber::fmt::Layer"><code>fmt::Layer</code></a> or <a href="../struct.Subscriber.html" title="struct tracing_subscriber::fmt::Subscriber"><code>fmt::Subscriber</code></a> to print
|
||||
formatted text representations of <a href="../../../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 <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a>, such
|
||||
as <a href="https://doc.rust-lang.org/1.84.1/std/io/stdio/fn.stdout.html" title="fn std::io::stdio::stdout"><code>io::stdout</code></a> and <a href="https://doc.rust-lang.org/1.84.1/std/io/stdio/fn.stderr.html" title="fn std::io::stdio::stderr"><code>io::stderr</code></a>. Additionally, it is implemented for
|
||||
<a href="https://doc.rust-lang.org/1.84.1/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
|
||||
<a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>The simplest usage is to pass in a named function that returns a writer. For
|
||||
example, to log all events to stderr, we could write:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>subscriber = tracing_subscriber::fmt()
|
||||
.with_writer(std::io::stderr)
|
||||
.finish();</code></pre></div>
|
||||
<p>Any function that returns a writer can be used:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">fn </span>make_my_great_writer() -> <span class="kw">impl </span>std::io::Write {
|
||||
<span class="comment">// ...
|
||||
</span>}
|
||||
|
||||
<span class="kw">let </span>subscriber = tracing_subscriber::fmt()
|
||||
.with_writer(make_my_great_writer)
|
||||
.finish();</code></pre></div>
|
||||
<p>A closure can be used to introduce arbitrary logic into how the writer is
|
||||
created. Consider the (admittedly rather silly) example of sending every 5th
|
||||
event to stderr, and all other events to stdout:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io;
|
||||
<span class="kw">use </span>std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
|
||||
|
||||
<span class="kw">let </span>n = AtomicUsize::new(<span class="number">0</span>);
|
||||
<span class="kw">let </span>subscriber = tracing_subscriber::fmt()
|
||||
.with_writer(<span class="kw">move </span>|| -> Box<<span class="kw">dyn </span>io::Write> {
|
||||
<span class="kw">if </span>n.fetch_add(<span class="number">1</span>, Relaxed) % <span class="number">5 </span>== <span class="number">0 </span>{
|
||||
Box::new(io::stderr())
|
||||
} <span class="kw">else </span>{
|
||||
Box::new(io::stdout())
|
||||
}
|
||||
})
|
||||
.finish();</code></pre></div>
|
||||
<p>A single instance of a type implementing <a href="https://doc.rust-lang.org/1.84.1/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 <a href="https://doc.rust-lang.org/1.84.1/std/sync/mutex/struct.Mutex.html" title="struct std::sync::mutex::Mutex"><code>Mutex</code></a>. For example, we could
|
||||
write to a file like so:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::{fs::File, sync::Mutex};
|
||||
|
||||
<span class="kw">let </span>log_file = File::create(<span class="string">"my_cool_trace.log"</span>)<span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>subscriber = tracing_subscriber::fmt()
|
||||
.with_writer(Mutex::new(log_file))
|
||||
.finish();</code></pre></div>
|
||||
</div></details><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.Writer" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#100">Source</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a>: <a class="trait" href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">Write</a></h4></section></summary><div class="docblock"><p>The concrete <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write"><code>io::Write</code></a> implementation returned by <a href="../trait.MakeWriter.html#tymethod.make_writer" title="method tracing_subscriber::fmt::MakeWriter::make_writer"><code>make_writer</code></a>.</p>
|
||||
</div></details></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.make_writer" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#115">Source</a><h4 class="code-header">fn <a href="#tymethod.make_writer" class="fn">make_writer</a>(&'a self) -> Self::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a></h4></section></summary><div class="docblock"><p>Returns an instance of <a href="../trait.MakeWriter.html#associatedtype.Writer" title="associated type tracing_subscriber::fmt::MakeWriter::Writer"><code>Writer</code></a>.</p>
|
||||
<h5 id="implementer-notes"><a class="doc-anchor" href="#implementer-notes">§</a>Implementer notes</h5>
|
||||
<p><a href="../struct.Layer.html" title="struct tracing_subscriber::fmt::Layer"><code>fmt::Layer</code></a> or <a href="../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 <a href="../trait.MakeWriter.html#associatedtype.Writer" title="associated type tracing_subscriber::fmt::MakeWriter::Writer"><code>Writer</code></a> instance is dropped. If
|
||||
creating a <a href="https://doc.rust-lang.org/1.84.1/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
|
||||
<a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> to improve performance.</p>
|
||||
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.make_writer_for" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#205-208">Source</a><h4 class="code-header">fn <a href="#method.make_writer_for" class="fn">make_writer_for</a>(&'a self, meta: &<a class="struct" href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata">Metadata</a><'_>) -> Self::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a></h4></section></summary><div class="docblock"><p>Returns a <a href="../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 <a href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata"><code>Metadata</code></a>.</p>
|
||||
<p>By default, this calls <a href="../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
|
||||
<a href="../../../tracing_core/metadata/struct.Level.html#associatedconstant.ERROR" title="associated constant tracing_core::metadata::Level::ERROR"><code>ERROR</code></a> and <a href="../../../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
|
||||
at lower levels to stdout:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io::{<span class="self">self</span>, Stdout, Stderr, StdoutLock, StderrLock};
|
||||
<span class="kw">use </span>tracing_subscriber::fmt::writer::MakeWriter;
|
||||
<span class="kw">use </span>tracing_core::{Metadata, Level};
|
||||
|
||||
<span class="kw">pub struct </span>MyMakeWriter {
|
||||
stdout: Stdout,
|
||||
stderr: Stderr,
|
||||
}
|
||||
|
||||
<span class="doccomment">/// A lock on either stdout or stderr, depending on the verbosity level
|
||||
/// of the event being written.
|
||||
</span><span class="kw">pub enum </span>StdioLock<<span class="lifetime">'a</span>> {
|
||||
Stdout(StdoutLock<<span class="lifetime">'a</span>>),
|
||||
Stderr(StderrLock<<span class="lifetime">'a</span>>),
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><<span class="lifetime">'a</span>> io::Write <span class="kw">for </span>StdioLock<<span class="lifetime">'a</span>> {
|
||||
<span class="kw">fn </span>write(<span class="kw-2">&mut </span><span class="self">self</span>, buf: <span class="kw-2">&</span>[u8]) -> io::Result<usize> {
|
||||
<span class="kw">match </span><span class="self">self </span>{
|
||||
StdioLock::Stdout(lock) => lock.write(buf),
|
||||
StdioLock::Stderr(lock) => lock.write(buf),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>write_all(<span class="kw-2">&mut </span><span class="self">self</span>, buf: <span class="kw-2">&</span>[u8]) -> io::Result<()> {
|
||||
<span class="comment">// ...
|
||||
</span>}
|
||||
|
||||
<span class="kw">fn </span>flush(<span class="kw-2">&mut </span><span class="self">self</span>) -> io::Result<()> {
|
||||
<span class="comment">// ...
|
||||
</span>}
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><<span class="lifetime">'a</span>> MakeWriter<<span class="lifetime">'a</span>> <span class="kw">for </span>MyMakeWriter {
|
||||
<span class="kw">type </span>Writer = StdioLock<<span class="lifetime">'a</span>>;
|
||||
|
||||
<span class="kw">fn </span>make_writer(<span class="kw-2">&</span><span class="lifetime">'a </span><span class="self">self</span>) -> <span class="self">Self</span>::Writer {
|
||||
<span class="comment">// We must have an implementation of `make_writer` that makes
|
||||
// a "default" writer without any configuring metadata. Let's
|
||||
// just return stdout in that case.
|
||||
</span>StdioLock::Stdout(<span class="self">self</span>.stdout.lock())
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>make_writer_for(<span class="kw-2">&</span><span class="lifetime">'a </span><span class="self">self</span>, meta: <span class="kw-2">&</span>Metadata<<span class="lifetime">'_</span>>) -> <span class="self">Self</span>::Writer {
|
||||
<span class="comment">// Here's where we can implement our special behavior. We'll
|
||||
// check if the metadata's verbosity level is WARN or ERROR,
|
||||
// and return stderr in that case.
|
||||
</span><span class="kw">if </span>meta.level() <= <span class="kw-2">&</span>Level::WARN {
|
||||
<span class="kw">return </span>StdioLock::Stderr(<span class="self">self</span>.stderr.lock());
|
||||
}
|
||||
|
||||
<span class="comment">// Otherwise, we'll return stdout.
|
||||
</span>StdioLock::Stdout(<span class="self">self</span>.stdout.lock())
|
||||
}
|
||||
}</code></pre></div>
|
||||
</div></details></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-File" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#697-702">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-File" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/fs/struct.File.html" title="struct std::fs::File">File</a></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-1" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#698">Source</a><a href="#associatedtype.Writer-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = &'a <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/fs/struct.File.html" title="struct std::fs::File">File</a></h4></section><section id="method.make_writer" class="method trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#699-701">Source</a><a href="#method.make_writer" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.make_writer" class="fn">make_writer</a>(&'a self) -> Self::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-Arc%3CW%3E" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#687-695">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-Arc%3CW%3E" class="anchor">§</a><h3 class="code-header">impl<'a, W> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc">Arc</a><W><div class="where">where
|
||||
<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&'a W</a>: <a class="trait" href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">Write</a> + 'a,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-2" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#691">Source</a><a href="#associatedtype.Writer-2" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&'a W</a></h4></section><section id="method.make_writer-1" class="method trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#692-694">Source</a><a href="#method.make_writer-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.make_writer" class="fn">make_writer</a>(&'a self) -> Self::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-Mutex%3CW%3E" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#792-801">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-Mutex%3CW%3E" class="anchor">§</a><h3 class="code-header">impl<'a, W> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/sync/mutex/struct.Mutex.html" title="struct std::sync::mutex::Mutex">Mutex</a><W><div class="where">where
|
||||
W: <a class="trait" href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">Write</a> + 'a,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-3" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#796">Source</a><a href="#associatedtype.Writer-3" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = <a class="struct" href="struct.MutexGuardWriter.html" title="struct tracing_subscriber::fmt::writer::MutexGuardWriter">MutexGuardWriter</a><'a, W></h4></section><section id="method.make_writer-2" class="method trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#798-800">Source</a><a href="#method.make_writer-2" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.make_writer" class="fn">make_writer</a>(&'a self) -> Self::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-TestWriter" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#725-731">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-TestWriter" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="../struct.TestWriter.html" title="struct tracing_subscriber::fmt::TestWriter">TestWriter</a></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-4" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#726">Source</a><a href="#associatedtype.Writer-4" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = <a class="struct" href="../struct.TestWriter.html" title="struct tracing_subscriber::fmt::TestWriter">TestWriter</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-BoxMakeWriter" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#757-769">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-BoxMakeWriter" class="anchor">§</a><h3 class="code-header">impl<'a> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="struct.BoxMakeWriter.html" title="struct tracing_subscriber::fmt::writer::BoxMakeWriter">BoxMakeWriter</a></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-5" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#758">Source</a><a href="#associatedtype.Writer-5" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">Write</a> + 'a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-Tee%3CA,+B%3E" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#1035-1051">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-Tee%3CA,+B%3E" class="anchor">§</a><h3 class="code-header">impl<'a, A, B> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="struct.Tee.html" title="struct tracing_subscriber::fmt::writer::Tee">Tee</a><A, B><div class="where">where
|
||||
A: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>,
|
||||
B: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-6" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#1040">Source</a><a href="#associatedtype.Writer-6" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = <a class="struct" href="struct.Tee.html" title="struct tracing_subscriber::fmt::writer::Tee">Tee</a><<A as <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>>::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a>, <B as <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>>::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a>></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-OrElse%3CA,+B%3E" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#1113-1136">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-OrElse%3CA,+B%3E" class="anchor">§</a><h3 class="code-header">impl<'a, A, B, W> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="struct.OrElse.html" title="struct tracing_subscriber::fmt::writer::OrElse">OrElse</a><A, B><div class="where">where
|
||||
A: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a, Writer = <a class="type" href="type.OptionalWriter.html" title="type tracing_subscriber::fmt::writer::OptionalWriter">OptionalWriter</a><W>>,
|
||||
B: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>,
|
||||
W: <a class="trait" href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">Write</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-7" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#1119">Source</a><a href="#associatedtype.Writer-7" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = <a class="enum" href="enum.EitherWriter.html" title="enum tracing_subscriber::fmt::writer::EitherWriter">EitherWriter</a><W, <B as <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>>::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a>></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-F" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#675-685">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-F" class="anchor">§</a><h3 class="code-header">impl<'a, F, W> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for F<div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> W,
|
||||
W: <a class="trait" href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">Write</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-8" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#680">Source</a><a href="#associatedtype.Writer-8" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = W</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-WithFilter%3CM,+F%3E" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#998-1018">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-WithFilter%3CM,+F%3E" class="anchor">§</a><h3 class="code-header">impl<'a, M, F> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="struct.WithFilter.html" title="struct tracing_subscriber::fmt::writer::WithFilter">WithFilter</a><M, F><div class="where">where
|
||||
M: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>,
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&<a class="struct" href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata">Metadata</a><'_>) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-9" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#1003">Source</a><a href="#associatedtype.Writer-9" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = <a class="enum" href="enum.EitherWriter.html" title="enum tracing_subscriber::fmt::writer::EitherWriter">EitherWriter</a><<M as <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>>::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a>, <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/io/util/struct.Sink.html" title="struct std::io::util::Sink">Sink</a>></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-WithMaxLevel%3CM%3E" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#928-944">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-WithMaxLevel%3CM%3E" class="anchor">§</a><h3 class="code-header">impl<'a, M: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="struct.WithMaxLevel.html" title="struct tracing_subscriber::fmt::writer::WithMaxLevel">WithMaxLevel</a><M></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-10" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#929">Source</a><a href="#associatedtype.Writer-10" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = <a class="enum" href="enum.EitherWriter.html" title="enum tracing_subscriber::fmt::writer::EitherWriter">EitherWriter</a><<M as <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>>::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a>, <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/io/util/struct.Sink.html" title="struct std::io::util::Sink">Sink</a>></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-MakeWriter%3C'a%3E-for-WithMinLevel%3CM%3E" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#961-977">Source</a><a href="#impl-MakeWriter%3C'a%3E-for-WithMinLevel%3CM%3E" class="anchor">§</a><h3 class="code-header">impl<'a, M: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>> <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> for <a class="struct" href="struct.WithMinLevel.html" title="struct tracing_subscriber::fmt::writer::WithMinLevel">WithMinLevel</a><M></h3></section></summary><div class="impl-items"><section id="associatedtype.Writer-11" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#962">Source</a><a href="#associatedtype.Writer-11" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Writer" class="associatedtype">Writer</a> = <a class="enum" href="enum.EitherWriter.html" title="enum tracing_subscriber::fmt::writer::EitherWriter">EitherWriter</a><<M as <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>>::<a class="associatedtype" href="../trait.MakeWriter.html#associatedtype.Writer" title="type tracing_subscriber::fmt::MakeWriter::Writer">Writer</a>, <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/io/util/struct.Sink.html" title="struct std::io::util::Sink">Sink</a>></h4></section></div></details></div><script src="../../../trait.impl/tracing_subscriber/fmt/writer/trait.MakeWriter.js" data-ignore-extern-crates="alloc,std" async></script></section></div></main></body></html>
|
||||
194
tracing_subscriber/fmt/writer/trait.MakeWriterExt.html
Normal file
194
tracing_subscriber/fmt/writer/trait.MakeWriterExt.html
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Extension trait adding combinators for working with types implementing `MakeWriter`."><title>MakeWriterExt in tracing_subscriber::fmt::writer - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-42caa33d.css"><meta name="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.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../../tracing_subscriber/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../../tracing_subscriber/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></a><h2><a href="../../../tracing_subscriber/index.html">tracing_<wbr>subscriber</a><span class="version">0.3.19</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Make<wbr>Writer<wbr>Ext</a></h2><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.and" title="and">and</a></li><li><a href="#method.or_else" title="or_else">or_else</a></li><li><a href="#method.with_filter" title="with_filter">with_filter</a></li><li><a href="#method.with_max_level" title="with_max_level">with_max_level</a></li><li><a href="#method.with_min_level" title="with_min_level">with_min_level</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In tracing_<wbr>subscriber::<wbr>fmt::<wbr>writer</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">tracing_subscriber</a>::<wbr><a href="../index.html">fmt</a>::<wbr><a href="index.html">writer</a></span><h1>Trait <span class="trait">MakeWriterExt</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/tracing_subscriber/fmt/writer.rs.html#217-491">Source</a> </span></div><pre class="rust item-decl"><code>pub trait MakeWriterExt<'a>: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> {
|
||||
// Provided methods
|
||||
fn <a href="#method.with_max_level" class="fn">with_max_level</a>(self, level: <a class="struct" href="../../../tracing_core/metadata/struct.Level.html" title="struct tracing_core::metadata::Level">Level</a>) -> <a class="struct" href="struct.WithMaxLevel.html" title="struct tracing_subscriber::fmt::writer::WithMaxLevel">WithMaxLevel</a><Self>
|
||||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
||||
<span class="item-spacer"></span> fn <a href="#method.with_min_level" class="fn">with_min_level</a>(self, level: <a class="struct" href="../../../tracing_core/metadata/struct.Level.html" title="struct tracing_core::metadata::Level">Level</a>) -> <a class="struct" href="struct.WithMinLevel.html" title="struct tracing_subscriber::fmt::writer::WithMinLevel">WithMinLevel</a><Self>
|
||||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
||||
<span class="item-spacer"></span> fn <a href="#method.with_filter" class="fn">with_filter</a><F>(self, filter: F) -> <a class="struct" href="struct.WithFilter.html" title="struct tracing_subscriber::fmt::writer::WithFilter">WithFilter</a><Self, F>
|
||||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&<a class="struct" href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata">Metadata</a><'_>) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a></span> { ... }
|
||||
<span class="item-spacer"></span> fn <a href="#method.and" class="fn">and</a><B>(self, other: B) -> <a class="struct" href="struct.Tee.html" title="struct tracing_subscriber::fmt::writer::Tee">Tee</a><Self, B> <a href="#" class="tooltip" data-notable-ty="Tee<Self, B>">ⓘ</a>
|
||||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
B: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
||||
<span class="item-spacer"></span> fn <a href="#method.or_else" class="fn">or_else</a><W, B>(self, other: B) -> <a class="struct" href="struct.OrElse.html" title="struct tracing_subscriber::fmt::writer::OrElse">OrElse</a><Self, B>
|
||||
<span class="where">where Self: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a, Writer = <a class="type" href="type.OptionalWriter.html" title="type tracing_subscriber::fmt::writer::OptionalWriter">OptionalWriter</a><W>> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
B: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
W: <a class="trait" href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">Write</a></span> { ... }
|
||||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extension trait adding combinators for working with types implementing
|
||||
<a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>.</p>
|
||||
<p>This is not intended to be implemented directly for user-defined
|
||||
<a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>s; instead, it should be imported when the desired methods are
|
||||
used.</p>
|
||||
</div></details><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.with_max_level" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#276-281">Source</a><h4 class="code-header">fn <a href="#method.with_max_level" class="fn">with_max_level</a>(self, level: <a class="struct" href="../../../tracing_core/metadata/struct.Level.html" title="struct tracing_core::metadata::Level">Level</a>) -> <a class="struct" href="struct.WithMaxLevel.html" title="struct tracing_subscriber::fmt::writer::WithMaxLevel">WithMaxLevel</a><Self><div class="where">where
|
||||
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Wraps <code>self</code> and returns a <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> that will only write output
|
||||
for events at or below the provided verbosity <a href="../../../tracing_core/metadata/struct.Level.html" title="struct tracing_core::metadata::Level"><code>Level</code></a>. For instance,
|
||||
<code>Level::TRACE</code> is considered to be _more verbose<code>than</code>Level::INFO`.</p>
|
||||
<p>Events whose level is more verbose than <code>level</code> will be ignored, and no
|
||||
output will be written.</p>
|
||||
<h5 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h5>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::Level;
|
||||
<span class="kw">use </span>tracing_subscriber::fmt::writer::MakeWriterExt;
|
||||
|
||||
<span class="comment">// Construct a writer that outputs events to `stderr` only if the span or
|
||||
// event's level is >= WARN (WARN and ERROR).
|
||||
</span><span class="kw">let </span>mk_writer = std::io::stderr.with_max_level(Level::WARN);
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();</code></pre></div>
|
||||
<p>Writing the <code>ERROR</code> and <code>WARN</code> levels to <code>stderr</code>, and everything else
|
||||
to <code>stdout</code>:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>
|
||||
<span class="kw">let </span>mk_writer = std::io::stderr
|
||||
.with_max_level(Level::WARN)
|
||||
.or_else(std::io::stdout);
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();</code></pre></div>
|
||||
<p>Writing the <code>ERROR</code> level to <code>stderr</code>, the <code>INFO</code> and <code>WARN</code> levels to
|
||||
<code>stdout</code>, and the <code>INFO</code> and DEBUG` levels to a file:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::{sync::Arc, fs::File};
|
||||
<span class="kw">let </span>debug_log = Arc::new(File::create(<span class="string">"debug.log"</span>)<span class="question-mark">?</span>);
|
||||
|
||||
<span class="kw">let </span>mk_writer = std::io::stderr
|
||||
.with_max_level(Level::ERROR)
|
||||
.or_else(std::io::stdout
|
||||
.with_max_level(Level::INFO)
|
||||
.and(debug_log.with_max_level(Level::DEBUG))
|
||||
);
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();</code></pre></div>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.with_min_level" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#318-323">Source</a><h4 class="code-header">fn <a href="#method.with_min_level" class="fn">with_min_level</a>(self, level: <a class="struct" href="../../../tracing_core/metadata/struct.Level.html" title="struct tracing_core::metadata::Level">Level</a>) -> <a class="struct" href="struct.WithMinLevel.html" title="struct tracing_subscriber::fmt::writer::WithMinLevel">WithMinLevel</a><Self><div class="where">where
|
||||
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Wraps <code>self</code> and returns a <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> that will only write output
|
||||
for events at or above the provided verbosity <a href="../../../tracing_core/metadata/struct.Level.html" title="struct tracing_core::metadata::Level"><code>Level</code></a>.</p>
|
||||
<p>Events whose level is less verbose than <code>level</code> will be ignored, and no
|
||||
output will be written.</p>
|
||||
<h5 id="examples-1"><a class="doc-anchor" href="#examples-1">§</a>Examples</h5>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::Level;
|
||||
<span class="kw">use </span>tracing_subscriber::fmt::writer::MakeWriterExt;
|
||||
|
||||
<span class="comment">// Construct a writer that outputs events to `stdout` only if the span or
|
||||
// event's level is <= DEBUG (DEBUG and TRACE).
|
||||
</span><span class="kw">let </span>mk_writer = std::io::stdout.with_min_level(Level::DEBUG);
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();</code></pre></div>
|
||||
<p>This can be combined with <a href="trait.MakeWriterExt.html#method.with_max_level" title="method tracing_subscriber::fmt::writer::MakeWriterExt::with_max_level"><code>MakeWriterExt::with_max_level</code></a> to write
|
||||
only within a range of levels:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// Only write the `DEBUG` and `INFO` levels to stdout.
|
||||
</span><span class="kw">let </span>mk_writer = std::io::stdout
|
||||
.with_max_level(Level::DEBUG)
|
||||
.with_min_level(Level::INFO)
|
||||
<span class="comment">// Write the `WARN` and `ERROR` levels to stderr.
|
||||
</span>.and(std::io::stderr.with_min_level(Level::WARN));
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();</code></pre></div>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.with_filter" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#397-403">Source</a><h4 class="code-header">fn <a href="#method.with_filter" class="fn">with_filter</a><F>(self, filter: F) -> <a class="struct" href="struct.WithFilter.html" title="struct tracing_subscriber::fmt::writer::WithFilter">WithFilter</a><Self, F><div class="where">where
|
||||
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&<a class="struct" href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata">Metadata</a><'_>) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Wraps <code>self</code> with a predicate that takes a span or event’s <a href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata"><code>Metadata</code></a>
|
||||
and returns a <code>bool</code>. The returned <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>’s
|
||||
<a href="../trait.MakeWriter.html#method.make_writer_for" title="method tracing_subscriber::fmt::MakeWriter::make_writer_for"><code>MakeWriter::make_writer_for</code></a> method will check the predicate to
|
||||
determine if a writer should be produced for a given span or event.</p>
|
||||
<p>If the predicate returns <code>false</code>, the wrapped <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>’s
|
||||
<a href="../trait.MakeWriter.html#method.make_writer_for" title="method tracing_subscriber::fmt::MakeWriter::make_writer_for"><code>make_writer_for</code></a> will return <a href="enum.EitherWriter.html#method.none" title="associated function tracing_subscriber::fmt::writer::EitherWriter::none"><code>OptionalWriter::none</code></a>.
|
||||
Otherwise, it calls the wrapped <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>’s
|
||||
<a href="../trait.MakeWriter.html#method.make_writer_for" title="method tracing_subscriber::fmt::MakeWriter::make_writer_for"><code>make_writer_for</code></a> method, and returns the produced writer.</p>
|
||||
<p>This can be used to filter an output based on arbitrary <a href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata"><code>Metadata</code></a>
|
||||
parameters.</p>
|
||||
<h5 id="examples-2"><a class="doc-anchor" href="#examples-2">§</a>Examples</h5>
|
||||
<p>Writing events with a specific target to an HTTP access log, and other
|
||||
events to stdout:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing_subscriber::fmt::writer::MakeWriterExt;
|
||||
<span class="kw">use </span>std::{sync::Arc, fs::File};
|
||||
<span class="kw">let </span>access_log = Arc::new(File::create(<span class="string">"access.log"</span>)<span class="question-mark">?</span>);
|
||||
|
||||
<span class="kw">let </span>mk_writer = access_log
|
||||
<span class="comment">// Only write events with the target "http::access_log" to the
|
||||
// access log file.
|
||||
</span>.with_filter(|meta| meta.target() == <span class="string">"http::access_log"</span>)
|
||||
<span class="comment">// Write events with all other targets to stdout.
|
||||
</span>.or_else(std::io::stdout);
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();</code></pre></div>
|
||||
<p>Conditionally enabling or disabling a log file:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing_subscriber::fmt::writer::MakeWriterExt;
|
||||
<span class="kw">use </span>std::{
|
||||
sync::{Arc, atomic::{AtomicBool, Ordering}},
|
||||
fs::File,
|
||||
};
|
||||
|
||||
<span class="kw">static </span>DEBUG_LOG_ENABLED: AtomicBool = AtomicBool::new(<span class="bool-val">false</span>);
|
||||
|
||||
<span class="comment">// Create the debug log file
|
||||
</span><span class="kw">let </span>debug_file = Arc::new(File::create(<span class="string">"debug.log"</span>)<span class="question-mark">?</span>)
|
||||
<span class="comment">// Enable the debug log only if the flag is enabled.
|
||||
</span>.with_filter(|<span class="kw">_</span>| DEBUG_LOG_ENABLED.load(Ordering::Acquire));
|
||||
|
||||
<span class="comment">// Always write to stdout
|
||||
</span><span class="kw">let </span>mk_writer = std::io::stdout
|
||||
<span class="comment">// Write to the debug file if it's enabled
|
||||
</span>.and(debug_file);
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();
|
||||
|
||||
<span class="comment">// ...
|
||||
|
||||
// Later, we can toggle on or off the debug log file.
|
||||
</span>DEBUG_LOG_ENABLED.store(<span class="bool-val">true</span>, Ordering::Release);</code></pre></div>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.and" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#452-458">Source</a><h4 class="code-header">fn <a href="#method.and" class="fn">and</a><B>(self, other: B) -> <a class="struct" href="struct.Tee.html" title="struct tracing_subscriber::fmt::writer::Tee">Tee</a><Self, B> <a href="#" class="tooltip" data-notable-ty="Tee<Self, B>">ⓘ</a><div class="where">where
|
||||
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
B: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Combines <code>self</code> with another type implementing <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>, returning
|
||||
a new <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> that produces <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">writers</a> that write to <em>both</em>
|
||||
outputs.</p>
|
||||
<p>If writing to either writer returns an error, the returned writer will
|
||||
return that error. However, both writers will still be written to before
|
||||
the error is returned, so it is possible for one writer to fail while
|
||||
the other is written to successfully.</p>
|
||||
<h5 id="examples-3"><a class="doc-anchor" href="#examples-3">§</a>Examples</h5>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing_subscriber::fmt::writer::MakeWriterExt;
|
||||
|
||||
<span class="comment">// Construct a writer that outputs events to `stdout` *and* `stderr`.
|
||||
</span><span class="kw">let </span>mk_writer = std::io::stdout.and(std::io::stderr);
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();</code></pre></div>
|
||||
<p><code>and</code> can be used in conjunction with filtering combinators. For
|
||||
example, if we want to write to a number of outputs depending on the
|
||||
level of an event, we could write:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::Level;
|
||||
<span class="kw">use </span>std::{sync::Arc, fs::File};
|
||||
<span class="kw">let </span>debug_log = Arc::new(File::create(<span class="string">"debug.log"</span>)<span class="question-mark">?</span>);
|
||||
|
||||
<span class="comment">// Write everything to the debug log.
|
||||
</span><span class="kw">let </span>mk_writer = debug_log
|
||||
<span class="comment">// Write the `ERROR` and `WARN` levels to stderr.
|
||||
</span>.and(std::io::stderr.with_max_level(Level::WARN))
|
||||
<span class="comment">// Write `INFO` to `stdout`.
|
||||
</span>.and(std::io::stdout
|
||||
.with_max_level(Level::INFO)
|
||||
.with_min_level(Level::INFO)
|
||||
);
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();</code></pre></div>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.or_else" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#483-490">Source</a><h4 class="code-header">fn <a href="#method.or_else" class="fn">or_else</a><W, B>(self, other: B) -> <a class="struct" href="struct.OrElse.html" title="struct tracing_subscriber::fmt::writer::OrElse">OrElse</a><Self, B><div class="where">where
|
||||
Self: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a, Writer = <a class="type" href="type.OptionalWriter.html" title="type tracing_subscriber::fmt::writer::OptionalWriter">OptionalWriter</a><W>> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
B: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
W: <a class="trait" href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">Write</a>,</div></h4></section></summary><div class="docblock"><p>Combines <code>self</code> with another type implementing <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a>, returning
|
||||
a new <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> that calls <code>other</code>’s <a href="../trait.MakeWriter.html#tymethod.make_writer" title="method tracing_subscriber::fmt::MakeWriter::make_writer"><code>make_writer</code></a> if <code>self</code>’s
|
||||
<code>make_writer</code> returns <a href="enum.EitherWriter.html#method.none" title="associated function tracing_subscriber::fmt::writer::EitherWriter::none"><code>OptionalWriter::none</code></a>.</p>
|
||||
<h5 id="examples-4"><a class="doc-anchor" href="#examples-4">§</a>Examples</h5>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing::Level;
|
||||
<span class="kw">use </span>tracing_subscriber::fmt::writer::MakeWriterExt;
|
||||
|
||||
<span class="comment">// Produces a writer that writes to `stderr` if the level is >= WARN,
|
||||
// or returns `OptionalWriter::none()` otherwise.
|
||||
</span><span class="kw">let </span>stderr = std::io::stderr.with_max_level(Level::WARN);
|
||||
|
||||
<span class="comment">// If the `stderr` `MakeWriter` is disabled by the max level filter,
|
||||
// write to stdout instead:
|
||||
</span><span class="kw">let </span>mk_writer = stderr.or_else(std::io::stdout);
|
||||
|
||||
tracing_subscriber::fmt().with_writer(mk_writer).init();</code></pre></div>
|
||||
</div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-MakeWriterExt%3C'a%3E-for-M" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#1205">Source</a><a href="#impl-MakeWriterExt%3C'a%3E-for-M" class="anchor">§</a><h3 class="code-header">impl<'a, M> <a class="trait" href="trait.MakeWriterExt.html" title="trait tracing_subscriber::fmt::writer::MakeWriterExt">MakeWriterExt</a><'a> for M<div class="where">where
|
||||
M: <a class="trait" href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter">MakeWriter</a><'a>,</div></h3></section></div><script src="../../../trait.impl/tracing_subscriber/fmt/writer/trait.MakeWriterExt.js" async></script><script type="text/json" id="notable-traits-data">{"Tee<Self, B>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Tee.html\" title=\"struct tracing_subscriber::fmt::writer::Tee\">Tee</a><A, B></code></h3><pre><code><div class=\"where\">impl<A, B> <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html\" title=\"trait std::io::Write\">Write</a> for <a class=\"struct\" href=\"struct.Tee.html\" title=\"struct tracing_subscriber::fmt::writer::Tee\">Tee</a><A, B><div class=\"where\">where\n A: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html\" title=\"trait std::io::Write\">Write</a>,\n B: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html\" title=\"trait std::io::Write\">Write</a>,</div></div>"}</script></section></div></main></body></html>
|
||||
15
tracing_subscriber/fmt/writer/type.OptionalWriter.html
Normal file
15
tracing_subscriber/fmt/writer/type.OptionalWriter.html
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A writer which may or may not be enabled."><title>OptionalWriter in tracing_subscriber::fmt::writer - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-42caa33d.css"><meta name="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.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc type"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../../tracing_subscriber/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../../tracing_subscriber/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></a><h2><a href="../../../tracing_subscriber/index.html">tracing_<wbr>subscriber</a><span class="version">0.3.19</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Optional<wbr>Writer</a></h2><h3><a href="#aliased-type">Aliased type</a></h3><h3><a href="#variants">Variants</a></h3><ul class="block variant"><li><a href="#variant.A" title="A">A</a></li><li><a href="#variant.B" title="B">B</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.none" title="none">none</a></li><li><a href="#method.some" title="some">some</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-From%3COption%3CT%3E%3E-for-EitherWriter%3CT,+Sink%3E" title="From<Option<T>>">From<Option<T>></a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In tracing_<wbr>subscriber::<wbr>fmt::<wbr>writer</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">tracing_subscriber</a>::<wbr><a href="../index.html">fmt</a>::<wbr><a href="index.html">writer</a></span><h1>Type Alias <span class="type">OptionalWriter</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/tracing_subscriber/fmt/writer.rs.html#567">Source</a> </span></div><pre class="rust item-decl"><code>pub type OptionalWriter<T> = <a class="enum" href="enum.EitherWriter.html" title="enum tracing_subscriber::fmt::writer::EitherWriter">EitherWriter</a><T, <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/io/util/struct.Sink.html" title="struct std::io::util::Sink">Sink</a>>;</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A <a href="https://doc.rust-lang.org/1.84.1/std/io/trait.Write.html" title="trait std::io::Write">writer</a> which may or may not be enabled.</p>
|
||||
<p>This may be used by <a href="../trait.MakeWriter.html" title="trait tracing_subscriber::fmt::MakeWriter"><code>MakeWriter</code></a> implementations that wish to
|
||||
conditionally enable or disable the returned writer based on a span or
|
||||
event’s <a href="../../../tracing_core/metadata/struct.Metadata.html" title="struct tracing_core::metadata::Metadata"><code>Metadata</code></a>.</p>
|
||||
</div></details><h2 id="aliased-type" class="section-header">Aliased Type<a href="#aliased-type" class="anchor">§</a></h2><pre class="rust item-decl"><code>enum OptionalWriter<T> {
|
||||
A(T),
|
||||
B(<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/io/util/struct.Sink.html" title="struct std::io::util::Sink">Sink</a>),
|
||||
}</code></pre><h2 id="variants" class="variants section-header">Variants<a href="#variants" class="anchor">§</a></h2><div class="variants"><section id="variant.A" class="variant"><a href="#variant.A" class="anchor">§</a><h3 class="code-header">A(T)</h3></section><div class="docblock"><p>A writer of type <code>A</code>.</p>
|
||||
</div><section id="variant.B" class="variant"><a href="#variant.B" class="anchor">§</a><h3 class="code-header">B(<a class="struct" href="https://doc.rust-lang.org/1.84.1/std/io/util/struct.Sink.html" title="struct std::io::util::Sink">Sink</a>)</h3></section><div class="docblock"><p>A writer of type <code>B</code>.</p>
|
||||
</div></div><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-EitherWriter%3CT,+Sink%3E" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#881-901">Source</a><a href="#impl-EitherWriter%3CT,+Sink%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="type" href="type.OptionalWriter.html" title="type tracing_subscriber::fmt::writer::OptionalWriter">OptionalWriter</a><T></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.none" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#890-892">Source</a><h4 class="code-header">pub fn <a href="#method.none" class="fn">none</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns a <a href="https://doc.rust-lang.org/1.84.1/std/io/util/fn.sink.html" title="fn std::io::util::sink">disabled writer</a>.</p>
|
||||
<p>Any bytes written to the returned writer are discarded.</p>
|
||||
<p>This is equivalent to returning <a href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html#variant.None" title="variant core::option::Option::None"><code>Option::None</code></a>.</p>
|
||||
</div></details><details class="toggle method-toggle" open><summary><section id="method.some" class="method"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#898-900">Source</a><h4 class="code-header">pub fn <a href="#method.some" class="fn">some</a>(t: T) -> Self</h4></section></summary><div class="docblock"><p>Returns an enabled writer of type <code>T</code>.</p>
|
||||
<p>This is equivalent to returning <a href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html#variant.Some" title="variant core::option::Option::Some"><code>Option::Some</code></a>.</p>
|
||||
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-From%3COption%3CT%3E%3E-for-EitherWriter%3CT,+Sink%3E" class="impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#903-911">Source</a><a href="#impl-From%3COption%3CT%3E%3E-for-EitherWriter%3CT,+Sink%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a><<a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>> for <a class="type" href="type.OptionalWriter.html" title="type tracing_subscriber::fmt::writer::OptionalWriter">OptionalWriter</a><T></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="../../../src/tracing_subscriber/fmt/writer.rs.html#905-910">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(opt: <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>) -> Self</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details></div><script src="../../../type.impl/tracing_subscriber/fmt/writer/enum.EitherWriter.js" data-self-path="tracing_subscriber::fmt::writer::OptionalWriter" async></script></section></div></main></body></html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue