<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="A lightweight logging facade."><title>log - Rust</title><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><linkrel="stylesheet"href="../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../static.files/rustdoc-ac92e1bbe349e143.css"><metaname="rustdoc-vars"data-root-path="../"data-static-root-path="../static.files/"data-current-crate="log"data-themes=""data-resource-suffix=""data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)"data-channel="1.76.0"data-search-js="search-2b6ce74ff89ae146.js"data-settings-js="settings-4313503d2e1961c2.js"><scriptsrc="../static.files/storage-f2adc0d6ca4d09fb.js"></script><scriptdefersrc="../crates.js"></script><scriptdefersrc="../static.files/main-305769736d49e732.js"></script><noscript><linkrel="stylesheet"href="../static.files/noscript-feafe1bb7466e4bd.css"></noscript><linkrel="icon"href="https://www.rust-lang.org/favicon.ico"></head><bodyclass="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="mobile-topbar"><buttonclass="sidebar-menu-toggle">☰</button><aclass="logo-container"href="../log/index.html"><imgsrc="https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png"alt=""></a></nav><navclass="sidebar"><divclass="sidebar-crate"><aclass="logo-container"href="../log/index.html"><imgsrc="https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png"alt="logo"></a><h2><ahref="../log/index.html">log</a><spanclass="version">0.4.21</span></h2></div><divclass="sidebar-elems"><ulclass="block">
<main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><divid="sidebar-button"tabindex="-1"><ahref="../log/all.html"title="show sidebar"></a></div><inputclass="search-input"name="search"aria-label="Run search in the documentation"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><divid="help-button"tabindex="-1"><ahref="../help.html"title="help">?</a></div><divid="settings-menu"tabindex="-1"><ahref="../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><sectionid="main-content"class="content"><divclass="main-heading"><h1>Crate <aclass="mod"href="#">log</a><buttonid="copy-path"title="Copy item path to clipboard"><imgsrc="../static.files/clipboard-7571035ce49a181d.svg"width="19"height="18"alt="Copy item path"></button></h1><spanclass="out-of-band"><aclass="src"href="../src/log/lib.rs.html#11-1839">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>A lightweight logging facade.</p>
<p>The <code>log</code> crate provides a single logging API that abstracts over the
actual logging implementation. Libraries can use the logging API provided
by this crate, and the consumer of those libraries can choose the logging
implementation that is most suitable for its use case.</p>
<p>If no logging implementation is selected, the facade falls back to a “noop”
implementation that ignores all log messages. The overhead in this case
is very small - just an integer load, comparison and jump.</p>
<p>A log request consists of a <em>target</em>, a <em>level</em>, and a <em>body</em>. A target is a
string which defaults to the module path of the location of the log request,
though that default may be overridden. Logger implementations typically use
the target to filter requests based on some user configuration.</p>
<h2id="usage"><ahref="#usage">Usage</a></h2>
<p>The basic use of the log crate is through the five logging macros: <ahref="./macro.error.html"><code>error!</code></a>,
<ahref="./macro.warn.html"><code>warn!</code></a>, <ahref="./macro.info.html"><code>info!</code></a>, <ahref="./macro.debug.html"><code>debug!</code></a> and <ahref="./macro.trace.html"><code>trace!</code></a>
where <code>error!</code> represents the highest-priority log messages
and <code>trace!</code> the lowest. The log messages are filtered by configuring
the log level to exclude messages with a lower priority.
Each of these macros accept format strings similarly to <ahref="https://doc.rust-lang.org/stable/std/macro.println.html"><code>println!</code></a>.</p>
<p>The 0.3 and 0.4 versions of the <code>log</code> crate are almost entirely compatible. Log messages
made using <code>log</code> 0.3 will forward transparently to a logger implementation using <code>log</code> 0.4. Log
messages made using <code>log</code> 0.4 will forward to a logger implementation using <code>log</code> 0.3, but the
module path and file name information associated with the message will unfortunately be lost.</p>
</div></details><h2id="macros"class="section-header"><ahref="#macros">Macros</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="macro"href="macro.debug.html"title="macro log::debug">debug</a></div><divclass="desc docblock-short">Logs a message at the debug level.</div></li><li><divclass="item-name"><aclass="macro"href="macro.error.html"title="macro log::error">error</a></div><divclass="desc docblock-short">Logs a message at the error level.</div></li><li><divclass="item-name"><aclass="macro"href="macro.info.html"title="macro log::info">info</a></div><divclass="desc docblock-short">Logs a message at the info level.</div></li><li><divclass="item-name"><aclass="macro"href="macro.log.html"title="macro log::log">log</a></div><divclass="desc docblock-short">The standard logging macro.</div></li><li><divclass="item-name"><aclass="macro"href="macro.log_enabled.html"title="macro log::log_enabled">log_enabled</a></div><divclass="desc docblock-short">Determines if a message logged at the specified level in that module will
be logged.</div></li><li><divclass="item-name"><aclass="macro"href="macro.trace.html"title="macro log::trace">trace</a></div><divclass="desc docblock-short">Logs a message at the trace level.</div></li><li><divclass="item-name"><aclass="macro"href="macro.warn.html"title="macro log::warn">warn</a></div><divclass="desc docblock-short">Logs a message at the warn level.</div></li></ul><h2id="structs"class="section-header"><ahref="#structs">Structs</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="struct"href="struct.Metadata.html"title="struct log::Metadata">Metadata</a></div><divclass="desc docblock-short">Metadata about a log message.</div></li><li><divclass="item-name"><aclass="struct"href="struct.MetadataBuilder.html"title="struct log::MetadataBuilder">MetadataBuilder</a></div><divclass="desc docblock-short">Builder for <ahref="struct.Metadata.html"><code>Metadata</code></a>.</div></li><li><divclass="item-name"><aclass="struct"href="struct.ParseLevelError.html"title="struct log::ParseLevelError">ParseLevelError</a></div><divclass="desc docblock-short">The type returned by <ahref="https://doc.rust-lang.org/std/str/trait.FromStr.html#tymethod.from_str"><code>from_str</code></a> when the string doesn’t match any of the log levels.</div></li><li><divclass="item-name"><aclass="struct"href="struct.Record.html"title="struct log::Record">Record</a></div><divclass="desc docblock-short">The “payload” of a log message.</div></li><li><divclass="item-name"><aclass="struct"href="struct.RecordBuilder.html"title="struct log::RecordBuilder">RecordBuilder</a></div><divclass="desc docblock-short">Builder for <ahref="struct.Record.html"><code>Record</code></a>.</div></li><li><divclass="item-name"><aclass="struct"href="struct.SetLoggerError.html"title="struct log::SetLoggerError">SetLoggerError</a></div><divclass="desc docblock-short">The type returned by <ahref="fn.set_logger.html"><code>set_logger</code></a> if <ahref="fn.set_logger.html"><code>set_logger</code></a> has already been called.</div></li></ul><h2id="enums"class="section-header"><ahref="#enums">Enums</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="enum"href="enum.Level.html"title="enum log::Level">Level</a></div><divclass="desc docblock-short">An enum representing the available verbosity levels of the logger.</div></li><li><divclass="item-name"><aclass="enum"href="enum.LevelFilter.html"title="enum log::LevelFilter">LevelFilter</a></div><divclass="desc docblock-short">An enum representing the available verbosity level filters of the logger.</div></li></ul><h2id="constants"class="section-header"><ahref="#constants">Constants</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="constant"href="constant.STATIC_MAX_LEVEL.html"title="constant log::STATIC_MAX_LEVEL">STATIC_MAX_LEVEL</a></div><divclass="desc docblock-short">The statically resolved maximum log level.</div></li></ul><h2id="traits"class="section-header"><ahref="#traits">Traits</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="trait"href="trait.Log.html"title="trait log::Log">Log</a></div><divclass="desc docblock-short">A trait encapsulating the operations required of a logger.</div></li></ul><h2id="functions"class="section-header"><ahref="#functions">Functions</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="fn"href="fn.logger.html"title="fn log::logger">logger</a></div><divclass="desc docblock-short">Returns a reference to the logger.</div></li><li><divclass="item-name"><aclass="fn"href="fn.max_level.html"title="fn log::max_level">max_level</a></div><divclass="desc docblock-short">Returns the current maximum log level.</div></li><li><divclass="item-name"><aclass="fn"href="fn.set_boxed_logger.html"title="fn log::set_boxed_logger">set_boxed_logger</a></div><divclass="desc docblock-short">Sets the global logger to a <code>Box<Log></code>.</div></li><li><divclass="item-name"><aclass="fn"href="fn.set_logger.html"title="fn log::set_logger"