67 lines
10 KiB
HTML
67 lines
10 KiB
HTML
<!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="Checks whether a span or event is enabled based on the provided metadata."><meta name="keywords" content="rust, rustlang, rust-lang, enabled"><title>enabled in tracing - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><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="../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../dark.css" disabled><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script src="../crates.js"></script><script defer src="../main.js"></script>
|
||
<noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc macro"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a class="sidebar-logo" href="../tracing/index.html"><div class="logo-container"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></div>
|
||
</a><div class="sidebar-elems"><h2 class="location">Other items in<br><a href="index.html">tracing</a></h2><div id="sidebar-vars" data-name="enabled" data-ty="macro" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../tracing/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></a><nav class="sub"><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="18" height="18" alt="Pick another theme!" src="../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img width="18" height="18" alt="Change settings" src="../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><h1 class="fqn"><span class="in-band">Macro <a href="index.html">tracing</a>::<wbr><a class="macro" href="#">enabled</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></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">−</span>]</a></span><a class="srclink" href="../src/tracing/macros.rs.html#888-940" title="goto source code">[src]</a></span></h1><div class="docblock item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules!</span> <span class="ident">enabled</span> {
|
||
(<span class="ident">target</span> : <span class="macro-nonterminal">$</span><span class="macro-nonterminal">target</span> : <span class="ident">expr</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">lvl</span> : <span class="ident">expr</span>, { $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">fields</span> : <span class="ident">tt</span>) <span class="op">*</span> }) => { ... };
|
||
(<span class="ident">target</span> : <span class="macro-nonterminal">$</span><span class="macro-nonterminal">target</span> : <span class="ident">expr</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">lvl</span> : <span class="ident">expr</span>) => { ... };
|
||
(<span class="ident">target</span> : <span class="macro-nonterminal">$</span><span class="macro-nonterminal">target</span> : <span class="ident">expr</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">lvl</span> : <span class="ident">expr</span>, $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">field</span> : <span class="ident">tt</span>) <span class="kw-2">*</span>) => { ... };
|
||
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">lvl</span> : <span class="ident">expr</span>, $(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">field</span> : <span class="ident">tt</span>) <span class="kw-2">*</span>) => { ... };
|
||
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">lvl</span> : <span class="ident">expr</span>) => { ... };
|
||
}</code></pre></div>
|
||
</div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Checks whether a span or event is <a href="trait.Subscriber.html#tymethod.enabled">enabled</a> based on the provided <a href="struct.Metadata.html">metadata</a>.</p>
|
||
<p>This macro is a specialized tool: it is intended to be used prior
|
||
to an expensive computation required <em>just</em> for that event, but
|
||
<em>cannot</em> be done as part of an argument to that event, such as
|
||
when multiple events are emitted (e.g., iterating over a collection
|
||
and emitting an event for each item).</p>
|
||
<h2 id="usage" class="section-header"><a href="#usage">Usage</a></h2>
|
||
<p><a href="trait.Subscriber.html">Subscribers</a> can make filtering decisions based all the data included in a
|
||
span or event’s <a href="struct.Metadata.html"><code>Metadata</code></a>. This means that it is possible for <code>enabled!</code>
|
||
to return a <em>false positive</em> (indicating that something would be enabled
|
||
when it actually would not be) or a <em>false negative</em> (indicating that
|
||
something would be disabled when it would actually be enabled).</p>
|
||
<p>This occurs when a subscriber is using a <em>more specific</em> filter than the
|
||
metadata provided to the <code>enabled!</code> macro. Some situations that can result
|
||
in false positives or false negatives include:</p>
|
||
<ul>
|
||
<li>If a subscriber is using a filter which may enable a span or event based
|
||
on field names, but <code>enabled!</code> is invoked without listing field names,
|
||
<code>enabled!</code> may return a false negative if a specific field name would
|
||
cause the subscriber to enable something that would otherwise be disabled.</li>
|
||
<li>If a subscriber is using a filter which enables or disables specific events by
|
||
file path and line number, a particular event may be enabled/disabled
|
||
even if an <code>enabled!</code> invocation with the same level, target, and fields
|
||
indicated otherwise.</li>
|
||
<li>The subscriber can choose to enable <em>only</em> spans or <em>only</em> events, which <code>enabled</code>
|
||
will not reflect.</li>
|
||
</ul>
|
||
<p><code>enabled!()</code> requires a <a href="struct.Level.html">level</a> argument, an optional <code>target:</code>
|
||
argument, and an optional set of field names. If the fields are not provided,
|
||
they are considered to be unknown. <code>enabled!</code> attempts to match the
|
||
syntax of <code>event!()</code> as closely as possible, which can be seen in the
|
||
examples below.</p>
|
||
<h2 id="examples" class="section-header"><a href="#examples">Examples</a></h2>
|
||
<p>If the current subscriber is interested in recording <code>DEBUG</code>-level spans and
|
||
events in the current file and module path, this will evaluate to true:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">tracing</span>::{<span class="ident">enabled</span>, <span class="ident">Level</span>};
|
||
|
||
<span class="kw">if</span> <span class="macro">enabled!</span>(<span class="ident">Level::DEBUG</span>) {
|
||
<span class="comment">// some expensive work...</span>
|
||
}</code></pre></div>
|
||
<p>If the current subscriber is interested in recording spans and events
|
||
in the current file and module path, with the target “my_crate”, and at the
|
||
level <code>DEBUG</code>, this will evaluate to true:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">if</span> <span class="macro">enabled!</span>(<span class="ident">target</span>: <span class="string">"my_crate"</span>, <span class="ident">Level::DEBUG</span>) {
|
||
<span class="comment">// some expensive work...</span>
|
||
}</code></pre></div>
|
||
<p>If the current subscriber is interested in recording spans and events
|
||
in the current file and module path, with the target “my_crate”, at
|
||
the level <code>DEBUG</code>, and with a field named “hello”, this will evaluate
|
||
to true:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">if</span> <span class="macro">enabled!</span>(<span class="ident">target</span>: <span class="string">"my_crate"</span>, <span class="ident">Level::DEBUG</span>, <span class="ident">hello</span>) {
|
||
<span class="comment">// some expensive work...</span>
|
||
}</code></pre></div>
|
||
</div></details></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="tracing" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.59.0 (9d1b2106e 2022-02-23)" ></div>
|
||
</body></html> |