Lines Matching full:log
1 //! Adapters for connecting unstructured log records from the `log` crate into
9 //! by the [`log`] crate.
13 //! - [`AsTrace`] and [`AsLog`] traits for converting between `tracing` and `log` types.
14 //! - [`LogTracer`], a [`log::Log`] implementation that consumes [`log::Record`]s
25 //! ## Convert log records to tracing `Event`s
27 //! To convert [`log::Record`]s as [`tracing::Event`]s, set `LogTracer` as the default
33 //! use log;
39 //! log::trace!("an example trace log");
44 //! This conversion does not convert unstructured data in log records (such as
45 //! values passed as format arguments to the `log!` macro) to structured
48 //! primary use-case for this library: making it possible to locate the log
49 //! records emitted by dependencies which use `log` within the context of a
54 //! Enabling the ["log" and "log-always" feature flags][flags] on the `tracing`
55 //! crate will cause all `tracing` spans and events to emit `log::Record`s as
60 //! Note that logger implementations that convert log records to trace events
62 //! log records (such as the `TraceLogger`), as doing so will result in the
66 //! If the logging of trace events generated from log records produced by the
67 //! `log` crate is desired, either the `log` crate should not be used to
69 //! required to avoid infinitely converting between `Event` and `log::Record`.
72 //! * `trace-logger`: enables an experimental `log` subscriber, deprecated since
74 //! * `log-tracer`: enables the `LogTracer` type (on by default)
78 //! logs emitted through the `log` crate (see [`Builder::with_interest_cache`]); requires `std`
103 #![doc(html_root_url = "https://docs.rs/tracing-log/0.1.3")]
144 #[cfg(feature = "log-tracer")]
145 #[cfg_attr(docsrs, doc(cfg(feature = "log-tracer")))]
152 #[cfg(feature = "log-tracer")]
153 #[cfg_attr(docsrs, doc(cfg(feature = "log-tracer")))]
161 note = "use the `tracing` crate's \"log\" feature flag instead"
171 pub use log;
173 #[cfg(all(feature = "interest-cache", feature = "log-tracer", feature = "std"))]
176 #[cfg(all(feature = "interest-cache", feature = "log-tracer", feature = "std"))]
179 doc(cfg(all(feature = "interest-cache", feature = "log-tracer", feature = "std")))
183 /// Format a log record as a trace event in the current span.
184 pub fn format_trace(record: &log::Record<'_>) -> io::Result<()> { in format_trace()
192 pub(crate) fn dispatch_record(record: &log::Record<'_>) { in dispatch_record()
222 /// Trait implemented for `tracing` types that can be converted to a `log`
225 /// The `log` type that this type can be converted into.
226 type Log; typedef
227 /// Returns the `log` equivalent of `self`.
228 fn as_log(&self) -> Self::Log; in as_log() argument
231 /// Trait implemented for `log` types that can be converted to a `tracing`
243 type Log = log::Metadata<'a>; typedef
244 fn as_log(&self) -> Self::Log { in as_log() argument
245 log::Metadata::builder() in as_log()
251 impl<'a> crate::sealed::Sealed for log::Metadata<'a> {}
253 impl<'a> AsTrace for log::Metadata<'a> {
258 "log record", in as_trace()
280 "log.target",
281 "log.module_path",
282 "log.file",
283 "log.line",
290 let target = fieldset.field("log.target").unwrap(); in new()
291 let module = fieldset.field("log.module_path").unwrap(); in new()
292 let file = fieldset.field("log.file").unwrap(); in new()
293 let line = fieldset.field("log.line").unwrap(); in new()
309 "log event",
310 "log",
366 level: log::Level, in loglevel_to_cs()
373 log::Level::Trace => (&TRACE_CS, &*TRACE_FIELDS, &TRACE_META), in loglevel_to_cs()
374 log::Level::Debug => (&DEBUG_CS, &*DEBUG_FIELDS, &DEBUG_META), in loglevel_to_cs()
375 log::Level::Info => (&INFO_CS, &*INFO_FIELDS, &INFO_META), in loglevel_to_cs()
376 log::Level::Warn => (&WARN_CS, &*WARN_FIELDS, &WARN_META), in loglevel_to_cs()
377 log::Level::Error => (&ERROR_CS, &*ERROR_FIELDS, &ERROR_META), in loglevel_to_cs()
381 impl<'a> crate::sealed::Sealed for log::Record<'a> {}
383 impl<'a> AsTrace for log::Record<'a> {
388 "log record", in as_trace()
403 type Log = log::Level; typedef
404 fn as_log(&self) -> log::Level { in as_log()
406 tracing_core::Level::ERROR => log::Level::Error, in as_log()
407 tracing_core::Level::WARN => log::Level::Warn, in as_log()
408 tracing_core::Level::INFO => log::Level::Info, in as_log()
409 tracing_core::Level::DEBUG => log::Level::Debug, in as_log()
410 tracing_core::Level::TRACE => log::Level::Trace, in as_log()
415 impl crate::sealed::Sealed for log::Level {}
417 impl AsTrace for log::Level {
422 log::Level::Error => tracing_core::Level::ERROR, in as_trace()
423 log::Level::Warn => tracing_core::Level::WARN, in as_trace()
424 log::Level::Info => tracing_core::Level::INFO, in as_trace()
425 log::Level::Debug => tracing_core::Level::DEBUG, in as_trace()
426 log::Level::Trace => tracing_core::Level::TRACE, in as_trace()
431 impl crate::sealed::Sealed for log::LevelFilter {}
433 impl AsTrace for log::LevelFilter {
438 log::LevelFilter::Off => tracing_core::LevelFilter::OFF, in as_trace()
439 log::LevelFilter::Error => tracing_core::LevelFilter::ERROR, in as_trace()
440 log::LevelFilter::Warn => tracing_core::LevelFilter::WARN, in as_trace()
441 log::LevelFilter::Info => tracing_core::LevelFilter::INFO, in as_trace()
442 log::LevelFilter::Debug => tracing_core::LevelFilter::DEBUG, in as_trace()
443 log::LevelFilter::Trace => tracing_core::LevelFilter::TRACE, in as_trace()
451 type Log = log::LevelFilter; typedef
453 fn as_log(&self) -> Self::Log { in as_log() argument
455 tracing_core::LevelFilter::OFF => log::LevelFilter::Off, in as_log()
456 tracing_core::LevelFilter::ERROR => log::LevelFilter::Error, in as_log()
457 tracing_core::LevelFilter::WARN => log::LevelFilter::Warn, in as_log()
458 tracing_core::LevelFilter::INFO => log::LevelFilter::Info, in as_log()
459 tracing_core::LevelFilter::DEBUG => log::LevelFilter::Debug, in as_log()
460 tracing_core::LevelFilter::TRACE => log::LevelFilter::Trace, in as_log()
464 /// Extends log `Event`s to provide complete `Metadata`.
466 /// In `tracing-log`, an `Event` produced by a log (through [`AsTrace`]) has an hard coded
467 /// "log" target and no `file`, `line`, or `module_path` attributes. This happens because `Event`
468 /// requires its `Metadata` to be `'static`, while [`log::Record`]s provide them with a generic
482 /// If this `Event` comes from a `log`, this method provides a new
484 /// from the original log, including `file`, `line`, `module_path`
486 /// Returns `None` is the `Event` is not issued from a `log`.
488 /// Returns whether this `Event` represents a log (from the `log` crate)
502 "log event", in normalized_metadata()
503 fields.target.unwrap_or("log"), in normalized_metadata()
579 fn test_callsite(level: log::Level) { in test_callsite()
580 let record = log::Record::builder() in test_callsite()
604 test_callsite(log::Level::Error); in error_callsite_is_correct()
609 test_callsite(log::Level::Warn); in warn_callsite_is_correct()
614 test_callsite(log::Level::Info); in info_callsite_is_correct()
619 test_callsite(log::Level::Debug); in debug_callsite_is_correct()
624 test_callsite(log::Level::Trace); in trace_callsite_is_correct()