mentat/docs/apis/rust/env_logger/struct.Builder.html
2018-06-22 12:08:32 +01:00

317 lines
No EOL
37 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="API documentation for the Rust `Builder` struct in crate `env_logger`.">
<meta name="keywords" content="rust, rustlang, rust-lang, Builder">
<title>env_logger::Builder - Rust</title>
<link rel="stylesheet" type="text/css" href="../normalize.css">
<link rel="stylesheet" type="text/css" href="../rustdoc.css"
id="mainThemeStyle">
<link rel="stylesheet" type="text/css" href="../dark.css">
<link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle">
<script src="../storage.js"></script>
<link rel="shortcut icon" href="http://www.rust-lang.org/favicon.ico">
</head>
<body class="rustdoc struct">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<div class="sidebar-menu">&#9776;</div>
<a href='../env_logger/index.html'><img src='http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a>
<p class='location'>Struct Builder</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.from_env">from_env</a><a href="#method.from_default_env">from_default_env</a><a href="#method.format">format</a><a href="#method.default_format">default_format</a><a href="#method.default_format_level">default_format_level</a><a href="#method.default_format_module_path">default_format_module_path</a><a href="#method.default_format_timestamp">default_format_timestamp</a><a href="#method.filter_module">filter_module</a><a href="#method.filter_level">filter_level</a><a href="#method.filter">filter</a><a href="#method.parse">parse</a><a href="#method.target">target</a><a href="#method.write_style">write_style</a><a href="#method.parse_write_style">parse_write_style</a><a href="#method.try_init">try_init</a><a href="#method.init">init</a><a href="#method.build">build</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Debug">Debug</a><a href="#impl-Default">Default</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a></div></div><p class='location'><a href='index.html'>env_logger</a></p><script>window.sidebarCurrent = {name: 'Builder', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
</nav>
<div class="theme-picker">
<button id="theme-picker" aria-label="Pick another theme!">
<img src="../brush.svg" width="18" alt="Pick another theme!">
</button>
<div id="theme-choices"></div>
</div>
<script src="../theme.js"></script>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content"><h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>env_logger</a>::<wbr><a class="struct" href=''>Builder</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a class='srclink' href='../src/env_logger/lib.rs.html#365-369' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust struct'>pub struct Builder { /* fields omitted */ }</pre></div><div class='docblock'><p><code>Builder</code> acts as builder for initializing a <code>Logger</code>.</p>
<p>It can be used to customize the log format, change the environment variable used
to provide the logging directives and also set the default log level filter.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">log</span>;
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">env_logger</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">env</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>::<span class="ident">Write</span>;
<span class="kw">use</span> <span class="ident">log</span>::<span class="ident">LevelFilter</span>;
<span class="kw">use</span> <span class="ident">env_logger</span>::<span class="ident">Builder</span>;
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">from_default_env</span>();
<span class="ident">builder</span>.<span class="ident">format</span>(<span class="op">|</span><span class="ident">buf</span>, <span class="ident">record</span><span class="op">|</span> <span class="macro">writeln</span><span class="macro">!</span>(<span class="ident">buf</span>, <span class="string">&quot;{} - {}&quot;</span>, <span class="ident">record</span>.<span class="ident">level</span>(), <span class="ident">record</span>.<span class="ident">args</span>()))
.<span class="ident">filter</span>(<span class="prelude-val">None</span>, <span class="ident">LevelFilter</span>::<span class="ident">Info</span>)
.<span class="ident">init</span>();
<span class="macro">error</span><span class="macro">!</span>(<span class="string">&quot;error message&quot;</span>);
<span class="macro">info</span><span class="macro">!</span>(<span class="string">&quot;info message&quot;</span>);
}</pre>
</div>
<h2 id='methods' class='small-section-header'>
Methods<a href='#methods' class='anchor'></a>
</h2>
<h3 id='impl' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="struct" href="../env_logger/struct.Builder.html" title="struct env_logger::Builder">Builder</a></code><a href='#impl' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#371-705' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.new' class='fnname'>new</a>() -&gt; <a class="struct" href="../env_logger/struct.Builder.html" title="struct env_logger::Builder">Builder</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#401-403' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Initializes the log builder with defaults.</p>
<p><strong>NOTE:</strong> This method won't read from any environment variables.
Use the <a href="#method.filter"><code>filter</code></a> and <a href="#method.write_style"><code>write_style</code></a> methods to configure the builder
or use <a href="#method.from_env"><code>from_env</code></a> or <a href="#method.from_default_env"><code>from_default_env</code></a> instead.</p>
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
<p>Create a new builder and configure filters and style:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">log</span>::<span class="ident">LevelFilter</span>;
<span class="kw">use</span> <span class="ident">env_logger</span>::{<span class="ident">Builder</span>, <span class="ident">WriteStyle</span>};
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">new</span>();
<span class="ident">builder</span>.<span class="ident">filter</span>(<span class="prelude-val">None</span>, <span class="ident">LevelFilter</span>::<span class="ident">Info</span>)
.<span class="ident">write_style</span>(<span class="ident">WriteStyle</span>::<span class="ident">Always</span>)
.<span class="ident">init</span>();</pre>
</div><h4 id='method.from_env' class="method"><span id='from_env.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.from_env' class='fnname'>from_env</a>&lt;'a, E&gt;(env: E) -&gt; Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;E: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="../env_logger/struct.Env.html" title="struct env_logger::Env">Env</a>&lt;'a&gt;&gt;,&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#433-449' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Initializes the log builder from the environment.</p>
<p>The variables used to read configuration from can be tweaked before
passing in.</p>
<h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1>
<p>Initialise a logger reading the log filter from an environment variable
called <code>MY_LOG</code>:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">env_logger</span>::<span class="ident">Builder</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">from_env</span>(<span class="string">&quot;MY_LOG&quot;</span>);
<span class="ident">builder</span>.<span class="ident">init</span>();</pre>
<p>Initialise a logger using the <code>MY_LOG</code> variable for filtering and
<code>MY_LOG_STYLE</code> for whether or not to write styles:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">env_logger</span>::{<span class="ident">Builder</span>, <span class="ident">Env</span>};
<span class="kw">let</span> <span class="ident">env</span> <span class="op">=</span> <span class="ident">Env</span>::<span class="ident">new</span>().<span class="ident">filter</span>(<span class="string">&quot;MY_LOG&quot;</span>).<span class="ident">write_style</span>(<span class="string">&quot;MY_LOG_STYLE&quot;</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">from_env</span>(<span class="ident">env</span>);
<span class="ident">builder</span>.<span class="ident">init</span>();</pre>
</div><h4 id='method.from_default_env' class="method"><span id='from_default_env.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.from_default_env' class='fnname'>from_default_env</a>() -&gt; Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#469-471' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Initializes the log builder from the environment using default variable names.</p>
<p>This method is a convenient way to call <code>from_env(Env::default())</code> without
having to use the <code>Env</code> type explicitly. The builder will use the
<a href="struct.Env.html#default-environment-variables">default environment variables</a>.</p>
<h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1>
<p>Initialise a logger using the default environment variables:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">env_logger</span>::<span class="ident">Builder</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">from_default_env</span>();
<span class="ident">builder</span>.<span class="ident">init</span>();</pre>
</div><h4 id='method.format' class="method"><span id='format.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.format' class='fnname'>format</a>&lt;F:&nbsp;'static&gt;(&amp;mut self, format: F) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;mut <a class="struct" href="../env_logger/fmt/struct.Formatter.html" title="struct env_logger::fmt::Formatter">Formatter</a>, &amp;<a class="struct" href="../log/struct.Record.html" title="struct log::Record">Record</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#499-504' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Sets the format function for formatting the log output.</p>
<p>This function is called on each record logged and should format the
log record and output it to the given <a href="fmt/struct.Formatter.html"><code>Formatter</code></a>.</p>
<p>The format function is expected to output the string directly to the
<code>Formatter</code> so that implementations can use the <a href="https://doc.rust-lang.org/std/fmt/index.html"><code>std::fmt</code></a> macros
to format and output without intermediate heap allocations. The default
<code>env_logger</code> formatter takes advantage of this.</p>
<h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1>
<p>Use a custom format to write only the log message:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>::<span class="ident">Write</span>;
<span class="kw">use</span> <span class="ident">env_logger</span>::<span class="ident">Builder</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">new</span>();
<span class="ident">builder</span>.<span class="ident">format</span>(<span class="op">|</span><span class="ident">buf</span>, <span class="ident">record</span><span class="op">|</span> <span class="macro">write</span><span class="macro">!</span>(<span class="ident">buf</span>, <span class="string">&quot;{}&quot;</span>, <span class="ident">record</span>.<span class="ident">args</span>()));</pre>
</div><h4 id='method.default_format' class="method"><span id='default_format.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.default_format' class='fnname'>default_format</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#509-512' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Use the default format.</p>
<p>This method will clear any custom format set on the builder.</p>
</div><h4 id='method.default_format_level' class="method"><span id='default_format_level.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.default_format_level' class='fnname'>default_format_level</a>(&amp;mut self, write: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#515-518' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Whether or not to write the level in the default format.</p>
</div><h4 id='method.default_format_module_path' class="method"><span id='default_format_module_path.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.default_format_module_path' class='fnname'>default_format_module_path</a>(&amp;mut self, write: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#521-524' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Whether or not to write the module path in the default format.</p>
</div><h4 id='method.default_format_timestamp' class="method"><span id='default_format_timestamp.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.default_format_timestamp' class='fnname'>default_format_timestamp</a>(&amp;mut self, write: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#527-530' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Whether or not to write the timestamp in the default format.</p>
</div><h4 id='method.filter_module' class="method"><span id='filter_module.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.filter_module' class='fnname'>filter_module</a>(&amp;mut self, module: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, level: <a class="enum" href="../log/enum.LevelFilter.html" title="enum log::LevelFilter">LevelFilter</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#550-553' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Adds a directive to the filter for a specific module.</p>
<h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1>
<p>Only include messages for warning and above for logs in <code>path::to::module</code>:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">log</span>::<span class="ident">LevelFilter</span>;
<span class="kw">use</span> <span class="ident">env_logger</span>::<span class="ident">Builder</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">new</span>();
<span class="ident">builder</span>.<span class="ident">filter_module</span>(<span class="string">&quot;path::to::module&quot;</span>, <span class="ident">LevelFilter</span>::<span class="ident">Info</span>);</pre>
</div><h4 id='method.filter_level' class="method"><span id='filter_level.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.filter_level' class='fnname'>filter_level</a>(&amp;mut self, level: <a class="enum" href="../log/enum.LevelFilter.html" title="enum log::LevelFilter">LevelFilter</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#573-576' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Adds a directive to the filter for all modules.</p>
<h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1>
<p>Only include messages for warning and above for logs in <code>path::to::module</code>:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">log</span>::<span class="ident">LevelFilter</span>;
<span class="kw">use</span> <span class="ident">env_logger</span>::<span class="ident">Builder</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">new</span>();
<span class="ident">builder</span>.<span class="ident">filter_level</span>(<span class="ident">LevelFilter</span>::<span class="ident">Info</span>);</pre>
</div><h4 id='method.filter' class="method"><span id='filter.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.filter' class='fnname'>filter</a>(&amp;mut self, module: <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>&gt;, level: <a class="enum" href="../log/enum.LevelFilter.html" title="enum log::LevelFilter">LevelFilter</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#599-604' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Adds filters to the logger.</p>
<p>The given module (if any) will log at most the specified level provided.
If no module is provided then the filter will apply to all log messages.</p>
<h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1>
<p>Only include messages for warning and above for logs in <code>path::to::module</code>:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">log</span>::<span class="ident">LevelFilter</span>;
<span class="kw">use</span> <span class="ident">env_logger</span>::<span class="ident">Builder</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">new</span>();
<span class="ident">builder</span>.<span class="ident">filter</span>(<span class="prelude-val">Some</span>(<span class="string">&quot;path::to::module&quot;</span>), <span class="ident">LevelFilter</span>::<span class="ident">Info</span>);</pre>
</div><h4 id='method.parse' class="method"><span id='parse.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.parse' class='fnname'>parse</a>(&amp;mut self, filters: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#610-613' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Parses the directives string in the same form as the <code>RUST_LOG</code>
environment variable.</p>
<p>See the module documentation for more details.</p>
</div><h4 id='method.target' class="method"><span id='target.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.target' class='fnname'>target</a>(&amp;mut self, target: <a class="enum" href="../env_logger/fmt/enum.Target.html" title="enum env_logger::fmt::Target">Target</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#630-633' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Sets the target for the log output.</p>
<p>Env logger can log to either stdout or stderr. The default is stderr.</p>
<h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1>
<p>Write log message to <code>stdout</code>:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">env_logger</span>::{<span class="ident">Builder</span>, <span class="ident">Target</span>};
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">new</span>();
<span class="ident">builder</span>.<span class="ident">target</span>(<span class="ident">Target</span>::<span class="ident">Stdout</span>);</pre>
</div><h4 id='method.write_style' class="method"><span id='write_style.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.write_style' class='fnname'>write_style</a>(&amp;mut self, write_style: <a class="enum" href="../env_logger/fmt/enum.WriteStyle.html" title="enum env_logger::fmt::WriteStyle">WriteStyle</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#651-654' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Sets whether or not styles will be written.</p>
<p>This can be useful in environments that don't support control characters
for setting colors.</p>
<h1 id="examples-9" class="section-header"><a href="#examples-9">Examples</a></h1>
<p>Never attempt to write styles:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">env_logger</span>::{<span class="ident">Builder</span>, <span class="ident">WriteStyle</span>};
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">builder</span> <span class="op">=</span> <span class="ident">Builder</span>::<span class="ident">new</span>();
<span class="ident">builder</span>.<span class="ident">write_style</span>(<span class="ident">WriteStyle</span>::<span class="ident">Never</span>);</pre>
</div><h4 id='method.parse_write_style' class="method"><span id='parse_write_style.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.parse_write_style' class='fnname'>parse_write_style</a>(&amp;mut self, write_style: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>Self</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#660-663' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Parses whether or not to write styles in the same form as the <code>RUST_LOG_STYLE</code>
environment variable.</p>
<p>See the module documentation for more details.</p>
</div><h4 id='method.try_init' class="method"><span id='try_init.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.try_init' class='fnname'>try_init</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="../log/struct.SetLoggerError.html" title="struct log::SetLoggerError">SetLoggerError</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#674-679' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Initializes the global logger with the built env logger.</p>
<p>This should be called early in the execution of a Rust program. Any log
events that occur before initialization will be ignored.</p>
<h1 id="errors" class="section-header"><a href="#errors">Errors</a></h1>
<p>This function will fail if it is called more than once, or if another
library has already initialized a global logger.</p>
</div><h4 id='method.init' class="method"><span id='init.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.init' class='fnname'>init</a>(&amp;mut self)</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#690-692' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Initializes the global logger with the built env logger.</p>
<p>This should be called early in the execution of a Rust program. Any log
events that occur before initialization will be ignored.</p>
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
<p>This function will panic if it is called more than once, or if another
library has already initialized a global logger.</p>
</div><h4 id='method.build' class="method"><span id='build.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.build' class='fnname'>build</a>(&amp;mut self) -&gt; <a class="struct" href="../env_logger/struct.Logger.html" title="struct env_logger::Logger">Logger</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#698-704' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Build an env logger.</p>
<p>The returned logger implements the <code>Log</code> trait and can be installed manually
or nested within another logger.</p>
</div></div>
<h2 id='implementations' class='small-section-header'>
Trait Implementations<a href='#implementations' class='anchor'></a>
</h2>
<div id='implementations-list'>
<h3 id='impl-Debug' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../env_logger/struct.Builder.html" title="struct env_logger::Builder">Builder</a></code><a href='#impl-Debug' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#956-963' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#957-962' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id='impl-Default' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="../env_logger/struct.Builder.html" title="struct env_logger::Builder">Builder</a></code><a href='#impl-Default' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#364' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.default' class="method"><span id='default.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -&gt; <a class="struct" href="../env_logger/struct.Builder.html" title="struct env_logger::Builder">Builder</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/env_logger/lib.rs.html#364' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns the &quot;default value&quot; for a type. <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default">Read more</a></p>
</div></div></div>
<h2 id='synthetic-implementations' class='small-section-header'>
Auto Trait Implementations<a href='#synthetic-implementations' class='anchor'></a>
</h2>
<div id='synthetic-implementations-list'>
<h3 id='impl-Send' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../env_logger/struct.Builder.html" title="struct env_logger::Builder">Builder</a></code><a href='#impl-Send' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../env_logger/struct.Builder.html" title="struct env_logger::Builder">Builder</a></code><a href='#impl-Sync' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></div></div></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt><kbd>?</kbd></dt>
<dd>Show this help dialog</dd>
<dt><kbd>S</kbd></dt>
<dd>Focus the search field</dd>
<dt><kbd></kbd></dt>
<dd>Move up in search results</dd>
<dt><kbd></kbd></dt>
<dd>Move down in search results</dd>
<dt><kbd></kbd></dt>
<dd>Switch tab</dd>
<dt><kbd>&#9166;</kbd></dt>
<dd>Go to active search result</dd>
<dt><kbd>+</kbd></dt>
<dd>Expand all sections</dd>
<dt><kbd>-</kbd></dt>
<dd>Collapse all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../";
window.currentCrate = "env_logger";
</script>
<script src="../main.js"></script>
<script defer src="../search-index.js"></script>
</body>
</html>