mirror of
https://github.com/edg-l/edlang.git
synced 2024-11-10 01:58:23 +00:00
68 lines
12 KiB
HTML
68 lines
12 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="Adapters for connecting unstructured log records from the `log` crate into the `tracing` ecosystem."><title>tracing_log - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="tracing_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" ><script src="../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[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">☰</button><a class="logo-container" href="../tracing_log/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_log/index.html"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></a><h2><a href="../tracing_log/index.html">tracing_log</a><span class="version">0.2.0</span></h2></div><div class="sidebar-elems"><ul class="block">
|
||
<li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><div class="sidebar-resizer"></div>
|
||
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../tracing_log/all.html" title="show sidebar"></a></div><input class="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"><div id="help-button" tabindex="-1"><a href="../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">tracing_log</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../src/tracing_log/lib.rs.html#1-600">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Adapters for connecting unstructured log records from the <code>log</code> crate into
|
||
the <code>tracing</code> ecosystem.</p>
|
||
<h2 id="overview"><a href="#overview">Overview</a></h2>
|
||
<p><a href="https://crates.io/crates/tracing"><code>tracing</code></a> is a framework for instrumenting Rust programs with context-aware,
|
||
structured, event-based diagnostic information. This crate provides
|
||
compatibility layers for using <code>tracing</code> alongside the logging facade provided
|
||
by the <a href="../log/index.html" title="mod log"><code>log</code></a> crate.</p>
|
||
<p>This crate provides:</p>
|
||
<ul>
|
||
<li><a href="trait.AsTrace.html" title="trait tracing_log::AsTrace"><code>AsTrace</code></a> and <a href="trait.AsLog.html" title="trait tracing_log::AsLog"><code>AsLog</code></a> traits for converting between <code>tracing</code> and <code>log</code> types.</li>
|
||
<li><a href="struct.LogTracer.html" title="struct tracing_log::LogTracer"><code>LogTracer</code></a>, a <a href="../log/trait.Log.html" title="trait log::Log"><code>log::Log</code></a> implementation that consumes <a href="../log/struct.Record.html" title="struct log::Record"><code>log::Record</code></a>s
|
||
and outputs them as <a href="https://docs.rs/tracing/latest/tracing/struct.Event.html"><code>tracing::Event</code></a>.</li>
|
||
</ul>
|
||
<p><em>Compiler support: <a href="#supported-rust-versions">requires <code>rustc</code> 1.56+</a></em></p>
|
||
<h2 id="usage"><a href="#usage">Usage</a></h2><h3 id="convert-log-records-to-tracing-events"><a href="#convert-log-records-to-tracing-events">Convert log records to tracing <code>Event</code>s</a></h3>
|
||
<p>To convert <a href="../log/struct.Record.html" title="struct log::Record"><code>log::Record</code></a>s as <a href="https://docs.rs/tracing/latest/tracing/struct.Event.html"><code>tracing::Event</code></a>s, set <code>LogTracer</code> as the default
|
||
logger by calling its <a href="struct.LogTracer.html#method.init" title="associated function tracing_log::LogTracer::init"><code>init</code></a> or <a href="struct.LogTracer.html#method.init_with_filter" title="associated function tracing_log::LogTracer::init_with_filter"><code>init_with_filter</code></a> methods.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tracing_log::LogTracer;
|
||
<span class="kw">use </span>log;
|
||
|
||
LogTracer::init()<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// will be available for Subscribers as a tracing Event
|
||
</span><span class="macro">log::trace!</span>(<span class="string">"an example trace log"</span>);</code></pre></div>
|
||
<p>This conversion does not convert unstructured data in log records (such as
|
||
values passed as format arguments to the <code>log!</code> macro) to structured
|
||
<code>tracing</code> fields. However, it <em>does</em> attach these new events to to the
|
||
span that was currently executing when the record was logged. This is the
|
||
primary use-case for this library: making it possible to locate the log
|
||
records emitted by dependencies which use <code>log</code> within the context of a
|
||
trace.</p>
|
||
<h3 id="convert-tracing-events-to-logs"><a href="#convert-tracing-events-to-logs">Convert tracing <code>Event</code>s to logs</a></h3>
|
||
<p>Enabling the <a href="https://docs.rs/tracing/latest/tracing/#crate-feature-flags">“log” and “log-always” feature flags</a> on the <code>tracing</code>
|
||
crate will cause all <code>tracing</code> spans and events to emit <code>log::Record</code>s as
|
||
they occur.</p>
|
||
<h3 id="caution-mixing-both-conversions"><a href="#caution-mixing-both-conversions">Caution: Mixing both conversions</a></h3>
|
||
<p>Note that <code>log::Logger</code> implementations that convert log records to trace events
|
||
should not be used with <code>Subscriber</code>s that convert trace events <em>back</em> into
|
||
<code>log</code> records, as doing so will result in the event recursing between the subscriber
|
||
and the logger forever (or, in real life, probably overflowing the call stack).</p>
|
||
<p>If the logging of trace events generated from log records produced by the
|
||
<code>log</code> crate is desired, either the <code>log</code> crate should not be used to
|
||
implement this logging, or an additional layer of filtering will be
|
||
required to avoid infinitely converting between <code>Event</code> and <code>log::Record</code>.</p>
|
||
<h3 id="feature-flags"><a href="#feature-flags">Feature Flags</a></h3>
|
||
<ul>
|
||
<li><code>std</code>: enables features that require the Rust standard library (on by default)</li>
|
||
<li><code>log-tracer</code>: enables the <code>LogTracer</code> type (on by default)</li>
|
||
<li><code>interest-cache</code>: makes it possible to configure an interest cache for
|
||
logs emitted through the <code>log</code> crate (see <a href="log_tracer::Builder::with_interest_cache"><code>Builder::with_interest_cache</code></a>); requires <code>std</code></li>
|
||
</ul>
|
||
<h3 id="supported-rust-versions"><a href="#supported-rust-versions">Supported Rust Versions</a></h3>
|
||
<p>Tracing is built against the latest stable release. The minimum supported
|
||
version is 1.56. The current Tracing version is not guaranteed to build on
|
||
Rust versions earlier than the minimum supported version.</p>
|
||
<p>Tracing follows the same compiler support policies as the rest of the Tokio
|
||
project. The current stable Rust compiler and the three most recent minor
|
||
versions before it will always be supported. For example, if the current
|
||
stable compiler version is 1.69, the minimum supported version will not be
|
||
increased past 1.66, three minor versions prior. Increasing the minimum
|
||
supported compiler version is not considered a semver breaking change as
|
||
long as doing so complies with this policy.</p>
|
||
</div></details><h2 id="reexports" class="section-header"><a href="#reexports">Re-exports</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.log"><code>pub use <a class="mod" href="../log/index.html" title="mod log">log</a>;</code></div></li></ul><h2 id="modules" class="section-header"><a href="#modules">Modules</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="log_tracer/index.html" title="mod tracing_log::log_tracer">log_tracer</a></div><div class="desc docblock-short">An adapter for converting <a href="../log/index.html" title="mod log"><code>log</code></a> records into <code>tracing</code> <code>Event</code>s.</div></li></ul><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.LogTracer.html" title="struct tracing_log::LogTracer">LogTracer</a></div><div class="desc docblock-short">A simple “logger” that converts all log records into <code>tracing</code> <code>Event</code>s.</div></li></ul><h2 id="traits" class="section-header"><a href="#traits">Traits</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.AsLog.html" title="trait tracing_log::AsLog">AsLog</a></div><div class="desc docblock-short">Trait implemented for <code>tracing</code> types that can be converted to a <code>log</code>
|
||
equivalent.</div></li><li><div class="item-name"><a class="trait" href="trait.AsTrace.html" title="trait tracing_log::AsTrace">AsTrace</a></div><div class="desc docblock-short">Trait implemented for <code>log</code> types that can be converted to a <code>tracing</code>
|
||
equivalent.</div></li><li><div class="item-name"><a class="trait" href="trait.NormalizeEvent.html" title="trait tracing_log::NormalizeEvent">NormalizeEvent</a></div><div class="desc docblock-short">Extends log <code>Event</code>s to provide complete <code>Metadata</code>.</div></li></ul><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.format_trace.html" title="fn tracing_log::format_trace">format_trace</a></div><div class="desc docblock-short">Format a log record as a trace event in the current span.</div></li></ul></section></div></main></body></html> |