summaryrefslogtreecommitdiffstats
path: root/vendor/tracing-subscriber-0.3.3/src/fmt/format
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/tracing-subscriber-0.3.3/src/fmt/format/json.rs (renamed from vendor/tracing-subscriber/src/fmt/format/json.rs)175
-rw-r--r--vendor/tracing-subscriber-0.3.3/src/fmt/format/mod.rs (renamed from vendor/tracing-subscriber/src/fmt/format/mod.rs)443
-rw-r--r--vendor/tracing-subscriber-0.3.3/src/fmt/format/pretty.rs (renamed from vendor/tracing-subscriber/src/fmt/format/pretty.rs)156
3 files changed, 90 insertions, 684 deletions
diff --git a/vendor/tracing-subscriber/src/fmt/format/json.rs b/vendor/tracing-subscriber-0.3.3/src/fmt/format/json.rs
index c2f4d3755..cc86f03c7 100644
--- a/vendor/tracing-subscriber/src/fmt/format/json.rs
+++ b/vendor/tracing-subscriber-0.3.3/src/fmt/format/json.rs
@@ -23,42 +23,25 @@ use tracing_serde::AsSerde;
#[cfg(feature = "tracing-log")]
use tracing_log::NormalizeEvent;
-/// Marker for [`Format`] that indicates that the newline-delimited JSON log
-/// format should be used.
+/// Marker for `Format` that indicates that the verbose JSON log format should be used.
///
-/// This formatter is intended for production use with systems where structured
-/// logs are consumed as JSON by analysis and viewing tools. The JSON output is
-/// not optimized for human readability; instead, it should be pretty-printed
-/// using external JSON tools such as `jq`, or using a JSON log viewer.
+/// The full format includes fields from all entered spans.
///
/// # Example Output
///
-/// <pre><font color="#4E9A06"><b>:;</b></font> <font color="#4E9A06">cargo</font> run --example fmt-json
-/// <font color="#4E9A06"><b> Finished</b></font> dev [unoptimized + debuginfo] target(s) in 0.08s
-/// <font color="#4E9A06"><b> Running</b></font> `target/debug/examples/fmt-json`
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821315Z&quot;,&quot;level&quot;:&quot;INFO&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;preparing to shave yaks&quot;,&quot;number_of_yaks&quot;:3},&quot;target&quot;:&quot;fmt_json&quot;}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821422Z&quot;,&quot;level&quot;:&quot;INFO&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;shaving yaks&quot;},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821495Z&quot;,&quot;level&quot;:&quot;TRACE&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;hello! I&apos;m gonna shave a yak&quot;,&quot;excitement&quot;:&quot;yay!&quot;},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;},{&quot;yak&quot;:1,&quot;name&quot;:&quot;shave&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821546Z&quot;,&quot;level&quot;:&quot;TRACE&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;yak shaved successfully&quot;},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;},{&quot;yak&quot;:1,&quot;name&quot;:&quot;shave&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821598Z&quot;,&quot;level&quot;:&quot;DEBUG&quot;,&quot;fields&quot;:{&quot;yak&quot;:1,&quot;shaved&quot;:true},&quot;target&quot;:&quot;yak_events&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821637Z&quot;,&quot;level&quot;:&quot;TRACE&quot;,&quot;fields&quot;:{&quot;yaks_shaved&quot;:1},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821684Z&quot;,&quot;level&quot;:&quot;TRACE&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;hello! I&apos;m gonna shave a yak&quot;,&quot;excitement&quot;:&quot;yay!&quot;},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;},{&quot;yak&quot;:2,&quot;name&quot;:&quot;shave&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821727Z&quot;,&quot;level&quot;:&quot;TRACE&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;yak shaved successfully&quot;},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;},{&quot;yak&quot;:2,&quot;name&quot;:&quot;shave&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821773Z&quot;,&quot;level&quot;:&quot;DEBUG&quot;,&quot;fields&quot;:{&quot;yak&quot;:2,&quot;shaved&quot;:true},&quot;target&quot;:&quot;yak_events&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821806Z&quot;,&quot;level&quot;:&quot;TRACE&quot;,&quot;fields&quot;:{&quot;yaks_shaved&quot;:2},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821909Z&quot;,&quot;level&quot;:&quot;TRACE&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;hello! I&apos;m gonna shave a yak&quot;,&quot;excitement&quot;:&quot;yay!&quot;},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;},{&quot;yak&quot;:3,&quot;name&quot;:&quot;shave&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.821956Z&quot;,&quot;level&quot;:&quot;WARN&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;could not locate yak&quot;},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;},{&quot;yak&quot;:3,&quot;name&quot;:&quot;shave&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.822006Z&quot;,&quot;level&quot;:&quot;DEBUG&quot;,&quot;fields&quot;:{&quot;yak&quot;:3,&quot;shaved&quot;:false},&quot;target&quot;:&quot;yak_events&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.822041Z&quot;,&quot;level&quot;:&quot;ERROR&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;failed to shave yak&quot;,&quot;yak&quot;:3,&quot;error&quot;:&quot;missing yak&quot;},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.822079Z&quot;,&quot;level&quot;:&quot;TRACE&quot;,&quot;fields&quot;:{&quot;yaks_shaved&quot;:2},&quot;target&quot;:&quot;fmt_json::yak_shave&quot;,&quot;spans&quot;:[{&quot;yaks&quot;:3,&quot;name&quot;:&quot;shaving_yaks&quot;}]}
-/// {&quot;timestamp&quot;:&quot;2022-02-15T18:47:10.822117Z&quot;,&quot;level&quot;:&quot;INFO&quot;,&quot;fields&quot;:{&quot;message&quot;:&quot;yak shaving completed&quot;,&quot;all_yaks_shaved&quot;:false},&quot;target&quot;:&quot;fmt_json&quot;}
-/// </pre>
+/// ```json
+/// {
+/// "timestamp":"Feb 20 11:28:15.096",
+/// "level":"INFO",
+/// "fields":{"message":"some message","key":"value"}
+/// "target":"mycrate",
+/// "span":{name":"leaf"},
+/// "spans":[{"name":"root"},{"name":"leaf"}],
+/// }
+/// ```
///
/// # Options
///
-/// This formatter exposes additional options to configure the structure of the
-/// output JSON objects:
-///
/// - [`Json::flatten_event`] can be used to enable flattening event fields into
/// the root
/// - [`Json::with_current_span`] can be used to control logging of the current
@@ -69,23 +52,9 @@ use tracing_log::NormalizeEvent;
/// By default, event fields are not flattened, and both current span and span
/// list are logged.
///
-/// # Valuable Support
-///
-/// Experimental support is available for using the [`valuable`] crate to record
-/// user-defined values as structured JSON. When the ["valuable" unstable
-/// feature][unstable] is enabled, types implementing [`valuable::Valuable`] will
-/// be recorded as structured JSON, rather than
-/// using their [`std::fmt::Debug`] implementations.
-///
-/// **Note**: This is an experimental feature. [Unstable features][unstable]
-/// must be enabled in order to use `valuable` support.
-///
-/// [`Json::flatten_event`]: Json::flatten_event()
-/// [`Json::with_current_span`]: Json::with_current_span()
-/// [`Json::with_span_list`]: Json::with_span_list()
-/// [`valuable`]: https://crates.io/crates/valuable
-/// [unstable]: crate#unstable-features
-/// [`valuable::Valuable`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html
+/// [`Json::flatten_event`]: #method.flatten_event
+/// [`Json::with_current_span`]: #method.with_current_span
+/// [`Json::with_span_list`]: #method.with_span_list
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Json {
pub(crate) flatten_event: bool,
@@ -274,18 +243,6 @@ where
serializer.serialize_entry("target", meta.target())?;
}
- if self.display_filename {
- if let Some(filename) = meta.file() {
- serializer.serialize_entry("filename", filename)?;
- }
- }
-
- if self.display_line_number {
- if let Some(line_number) = meta.line() {
- serializer.serialize_entry("line_number", &line_number)?;
- }
- }
-
if self.format.display_current_span {
if let Some(ref span) = current_span {
serializer
@@ -341,6 +298,7 @@ impl Default for Json {
/// The JSON [`FormatFields`] implementation.
///
+/// [`FormatFields`]: trait.FormatFields.html
#[derive(Debug)]
pub struct JsonFields {
// reserve the ability to add fields to this without causing a breaking
@@ -351,6 +309,7 @@ pub struct JsonFields {
impl JsonFields {
/// Returns a new JSON [`FormatFields`] implementation.
///
+ /// [`FormatFields`]: trait.FormatFields.html
pub fn new() -> Self {
Self { _private: () }
}
@@ -419,8 +378,9 @@ impl<'a> FormatFields<'a> for JsonFields {
/// The [visitor] produced by [`JsonFields`]'s [`MakeVisitor`] implementation.
///
-/// [visitor]: crate::field::Visit
-/// [`MakeVisitor`]: crate::field::MakeVisitor
+/// [visitor]: ../../field/trait.Visit.html
+/// [`JsonFields`]: struct.JsonFields.html
+/// [`MakeVisitor`]: ../../field/trait.MakeVisitor.html
pub struct JsonVisitor<'a> {
values: BTreeMap<&'a str, serde_json::Value>,
writer: &'a mut dyn Write,
@@ -475,26 +435,6 @@ impl<'a> crate::field::VisitOutput<fmt::Result> for JsonVisitor<'a> {
}
impl<'a> field::Visit for JsonVisitor<'a> {
- #[cfg(all(tracing_unstable, feature = "valuable"))]
- fn record_value(&mut self, field: &Field, value: valuable_crate::Value<'_>) {
- let value = match serde_json::to_value(valuable_serde::Serializable::new(value)) {
- Ok(value) => value,
- Err(_e) => {
- #[cfg(debug_assertions)]
- unreachable!(
- "`valuable::Valuable` implementations should always serialize \
- successfully, but an error occurred: {}",
- _e,
- );
-
- #[cfg(not(debug_assertions))]
- return;
- }
- };
-
- self.values.insert(field.name(), value);
- }
-
/// Visit a double precision floating point value.
fn record_f64(&mut self, field: &Field, value: f64) {
self.values
@@ -548,7 +488,6 @@ mod test {
use tracing::{self, subscriber::with_default};
use std::fmt;
- use std::path::Path;
struct MockTime;
impl FormatTime for MockTime {
@@ -577,50 +516,6 @@ mod test {
}
#[test]
- fn json_filename() {
- let current_path = Path::new("tracing-subscriber")
- .join("src")
- .join("fmt")
- .join("format")
- .join("json.rs")
- .to_str()
- .expect("path must be valid unicode")
- // escape windows backslashes
- .replace('\\', "\\\\");
- let expected =
- &format!("{}{}{}",
- "{\"timestamp\":\"fake time\",\"level\":\"INFO\",\"span\":{\"answer\":42,\"name\":\"json_span\",\"number\":3},\"spans\":[{\"answer\":42,\"name\":\"json_span\",\"number\":3}],\"target\":\"tracing_subscriber::fmt::format::json::test\",\"filename\":\"",
- current_path,
- "\",\"fields\":{\"message\":\"some json test\"}}\n");
- let subscriber = subscriber()
- .flatten_event(false)
- .with_current_span(true)
- .with_file(true)
- .with_span_list(true);
- test_json(expected, subscriber, || {
- let span = tracing::span!(tracing::Level::INFO, "json_span", answer = 42, number = 3);
- let _guard = span.enter();
- tracing::info!("some json test");
- });
- }
-
- #[test]
- fn json_line_number() {
- let expected =
- "{\"timestamp\":\"fake time\",\"level\":\"INFO\",\"span\":{\"answer\":42,\"name\":\"json_span\",\"number\":3},\"spans\":[{\"answer\":42,\"name\":\"json_span\",\"number\":3}],\"target\":\"tracing_subscriber::fmt::format::json::test\",\"line_number\":42,\"fields\":{\"message\":\"some json test\"}}\n";
- let subscriber = subscriber()
- .flatten_event(false)
- .with_current_span(true)
- .with_line_number(true)
- .with_span_list(true);
- test_json_with_line_number(expected, subscriber, || {
- let span = tracing::span!(tracing::Level::INFO, "json_span", answer = 42, number = 3);
- let _guard = span.enter();
- tracing::info!("some json test");
- });
- }
-
- #[test]
fn json_flattened_event() {
let expected =
"{\"timestamp\":\"fake time\",\"level\":\"INFO\",\"span\":{\"answer\":42,\"name\":\"json_span\",\"number\":3},\"spans\":[{\"answer\":42,\"name\":\"json_span\",\"number\":3}],\"target\":\"tracing_subscriber::fmt::format::json::test\",\"message\":\"some json test\"}\n";
@@ -852,34 +747,4 @@ mod test {
serde_json::from_str(actual).unwrap()
);
}
-
- fn test_json_with_line_number<T>(
- expected: &str,
- builder: crate::fmt::SubscriberBuilder<JsonFields, Format<Json>>,
- producer: impl FnOnce() -> T,
- ) {
- let make_writer = MockMakeWriter::default();
- let subscriber = builder
- .with_writer(make_writer.clone())
- .with_timer(MockTime)
- .finish();
-
- with_default(subscriber, producer);
-
- let buf = make_writer.buf();
- let actual = std::str::from_utf8(&buf[..]).unwrap();
- let mut expected =
- serde_json::from_str::<std::collections::HashMap<&str, serde_json::Value>>(expected)
- .unwrap();
- let expect_line_number = expected.remove("line_number").is_some();
- let mut actual: std::collections::HashMap<&str, serde_json::Value> =
- serde_json::from_str(actual).unwrap();
- let line_number = actual.remove("line_number");
- if expect_line_number {
- assert_eq!(line_number.map(|x| x.is_number()), Some(true));
- } else {
- assert!(line_number.is_none());
- }
- assert_eq!(actual, expected);
- }
}
diff --git a/vendor/tracing-subscriber/src/fmt/format/mod.rs b/vendor/tracing-subscriber-0.3.3/src/fmt/format/mod.rs
index ec79ac140..9001e102e 100644
--- a/vendor/tracing-subscriber/src/fmt/format/mod.rs
+++ b/vendor/tracing-subscriber-0.3.3/src/fmt/format/mod.rs
@@ -1,33 +1,4 @@
//! Formatters for logging `tracing` events.
-//!
-//! This module provides several formatter implementations, as well as utilities
-//! for implementing custom formatters.
-//!
-//! # Formatters
-//! This module provides a number of formatter implementations:
-//!
-//! * [`Full`]: The default formatter. This emits human-readable,
-//! single-line logs for each event that occurs, with the current span context
-//! displayed before the formatted representation of the event. See
-//! [here](Full#example-output) for sample output.
-//!
-//! * [`Compact`]: A variant of the default formatter, optimized for
-//! short line lengths. Fields from the current span context are appended to
-//! the fields of the formatted event, and span names are not shown; the
-//! verbosity level is abbreviated to a single character. See
-//! [here](Compact#example-output) for sample output.
-//!
-//! * [`Pretty`]: Emits excessively pretty, multi-line logs, optimized
-//! for human readability. This is primarily intended to be used in local
-//! development and debugging, or for command-line applications, where
-//! automated analysis and compact storage of logs is less of a priority than
-//! readability and visual appeal. See [here](Pretty#example-output)
-//! for sample output.
-//!
-//! * [`Json`]: Outputs newline-delimited JSON logs. This is intended
-//! for production use with systems where structured logs are consumed as JSON
-//! by analysis and viewing tools. The JSON output is not optimized for human
-//! readability. See [here](Json#example-output) for sample output.
use super::time::{FormatTime, SystemTime};
use crate::{
field::{MakeOutput, MakeVisitor, RecordFields, VisitFmt, VisitOutput},
@@ -182,7 +153,6 @@ pub use pretty::*;
/// DEBUG yak_shaving::shaver: some-span{field-on-span=foo}: started shaving yak
/// ```
///
-/// [`layer::Context`]: crate::layer::Context
/// [`fmt::Layer`]: super::Layer
/// [`fmt::Subscriber`]: super::Subscriber
/// [`Event`]: tracing::Event
@@ -227,8 +197,8 @@ where
/// time a span or event with fields is recorded, the subscriber will format
/// those fields with its associated `FormatFields` implementation.
///
-/// [set of fields]: crate::field::RecordFields
-/// [`FmtSubscriber`]: super::Subscriber
+/// [set of fields]: ../field/trait.RecordFields.html
+/// [`FmtSubscriber`]: ../fmt/struct.Subscriber.html
pub trait FormatFields<'writer> {
/// Format the provided `fields` to the provided [`Writer`], returning a result.
fn format_fields<R: RecordFields>(&self, writer: Writer<'writer>, fields: R) -> fmt::Result;
@@ -281,6 +251,7 @@ pub fn json() -> Format<Json> {
/// Returns a [`FormatFields`] implementation that formats fields using the
/// provided function or closure.
///
+/// [`FormatFields`]: trait.FormatFields.html
pub fn debug_fn<F>(f: F) -> FieldFn<F>
where
F: Fn(&mut Writer<'_>, &Field, &dyn fmt::Debug) -> fmt::Result + Clone,
@@ -301,8 +272,6 @@ where
///
/// Additionally, a `Writer` may expose additional `tracing`-specific
/// information to the formatter implementation.
-///
-/// [fields]: tracing_core::field
pub struct Writer<'writer> {
writer: &'writer mut dyn fmt::Write,
// TODO(eliza): add ANSI support
@@ -312,76 +281,28 @@ pub struct Writer<'writer> {
/// A [`FormatFields`] implementation that formats fields by calling a function
/// or closure.
///
+/// [`FormatFields`]: trait.FormatFields.html
#[derive(Debug, Clone)]
pub struct FieldFn<F>(F);
/// The [visitor] produced by [`FieldFn`]'s [`MakeVisitor`] implementation.
///
-/// [visitor]: super::super::field::Visit
-/// [`MakeVisitor`]: super::super::field::MakeVisitor
+/// [visitor]: ../../field/trait.Visit.html
+/// [`FieldFn`]: struct.FieldFn.html
+/// [`MakeVisitor`]: ../../field/trait.MakeVisitor.html
pub struct FieldFnVisitor<'a, F> {
f: F,
writer: Writer<'a>,
result: fmt::Result,
}
-/// Marker for [`Format`] that indicates that the compact log format should be used.
-///
-/// The compact format includes fields from all currently entered spans, after
-/// the event's fields. Span names are listed in order before fields are
-/// displayed.
-///
-/// # Example Output
+/// Marker for `Format` that indicates that the compact log format should be used.
///
-/// <pre><font color="#4E9A06"><b>:;</b></font> <font color="#4E9A06">cargo</font> run --example fmt-compact
-/// <font color="#4E9A06"><b> Finished</b></font> dev [unoptimized + debuginfo] target(s) in 0.08s
-/// <font color="#4E9A06"><b> Running</b></font> `target/debug/examples/fmt-compact`
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809287Z </font><font color="#4E9A06"> INFO</font> <b>fmt_compact</b><font color="#AAAAAA">: preparing to shave yaks </font><i>number_of_yaks</i><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809367Z </font><font color="#4E9A06"> INFO</font> <b>shaving_yaks</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: shaving yaks </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809414Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks</b>:<b>shave</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: hello! I&apos;m gonna shave a yak </font><i>excitement</i><font color="#AAAAAA">=&quot;yay!&quot; </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3 </font><font color="#AAAAAA"><i>yak</i></font><font color="#AAAAAA">=1</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809443Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks</b>:<b>shave</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: yak shaved successfully </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3 </font><font color="#AAAAAA"><i>yak</i></font><font color="#AAAAAA">=1</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809477Z </font><font color="#3465A4">DEBUG</font> <b>shaving_yaks</b>: <b>yak_events</b><font color="#AAAAAA">: </font><i>yak</i><font color="#AAAAAA">=1 </font><i>shaved</i><font color="#AAAAAA">=true </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809500Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: </font><i>yaks_shaved</i><font color="#AAAAAA">=1 </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809531Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks</b>:<b>shave</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: hello! I&apos;m gonna shave a yak </font><i>excitement</i><font color="#AAAAAA">=&quot;yay!&quot; </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3 </font><font color="#AAAAAA"><i>yak</i></font><font color="#AAAAAA">=2</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809554Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks</b>:<b>shave</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: yak shaved successfully </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3 </font><font color="#AAAAAA"><i>yak</i></font><font color="#AAAAAA">=2</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809581Z </font><font color="#3465A4">DEBUG</font> <b>shaving_yaks</b>: <b>yak_events</b><font color="#AAAAAA">: </font><i>yak</i><font color="#AAAAAA">=2 </font><i>shaved</i><font color="#AAAAAA">=true </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809606Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: </font><i>yaks_shaved</i><font color="#AAAAAA">=2 </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809635Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks</b>:<b>shave</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: hello! I&apos;m gonna shave a yak </font><i>excitement</i><font color="#AAAAAA">=&quot;yay!&quot; </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3 </font><font color="#AAAAAA"><i>yak</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809664Z </font><font color="#C4A000"> WARN</font> <b>shaving_yaks</b>:<b>shave</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: could not locate yak </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3 </font><font color="#AAAAAA"><i>yak</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809693Z </font><font color="#3465A4">DEBUG</font> <b>shaving_yaks</b>: <b>yak_events</b><font color="#AAAAAA">: </font><i>yak</i><font color="#AAAAAA">=3 </font><i>shaved</i><font color="#AAAAAA">=false </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809717Z </font><font color="#CC0000">ERROR</font> <b>shaving_yaks</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: failed to shave yak </font><i>yak</i><font color="#AAAAAA">=3 </font><i>error</i><font color="#AAAAAA">=missing yak </font><i>error.sources</i><font color="#AAAAAA">=[out of space, out of cash] </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809743Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks</b>: <b>fmt_compact::yak_shave</b><font color="#AAAAAA">: </font><i>yaks_shaved</i><font color="#AAAAAA">=2 </font><font color="#AAAAAA"><i>yaks</i></font><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-17T19:51:05.809768Z </font><font color="#4E9A06"> INFO</font> <b>fmt_compact</b><font color="#AAAAAA">: yak shaving completed </font><i>all_yaks_shaved</i><font color="#AAAAAA">=false</font>
-///
-/// </pre>
+/// The compact format only includes the fields from the most recently entered span.
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct Compact;
-/// Marker for [`Format`] that indicates that the default log format should be used.
-///
-/// This formatter shows the span context before printing event data. Spans are
-/// displayed including their names and fields.
+/// Marker for `Format` that indicates that the verbose log format should be used.
///
-/// # Example Output
-///
-/// <pre><font color="#4E9A06"><b>:;</b></font> <font color="#4E9A06">cargo</font> run --example fmt
-/// <font color="#4E9A06"><b> Finished</b></font> dev [unoptimized + debuginfo] target(s) in 0.08s
-/// <font color="#4E9A06"><b> Running</b></font> `target/debug/examples/fmt`
-/// <font color="#AAAAAA">2022-02-15T18:40:14.289898Z </font><font color="#4E9A06"> INFO</font> fmt: preparing to shave yaks <i>number_of_yaks</i><font color="#AAAAAA">=3</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.289974Z </font><font color="#4E9A06"> INFO</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: shaving yaks</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290011Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">:</font><b>shave{</b><i>yak</i><font color="#AAAAAA">=1</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: hello! I&apos;m gonna shave a yak </font><i>excitement</i><font color="#AAAAAA">=&quot;yay!&quot;</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290038Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">:</font><b>shave{</b><i>yak</i><font color="#AAAAAA">=1</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: yak shaved successfully</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290070Z </font><font color="#3465A4">DEBUG</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: yak_events: </font><i>yak</i><font color="#AAAAAA">=1 </font><i>shaved</i><font color="#AAAAAA">=true</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290089Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: </font><i>yaks_shaved</i><font color="#AAAAAA">=1</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290114Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">:</font><b>shave{</b><i>yak</i><font color="#AAAAAA">=2</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: hello! I&apos;m gonna shave a yak </font><i>excitement</i><font color="#AAAAAA">=&quot;yay!&quot;</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290134Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">:</font><b>shave{</b><i>yak</i><font color="#AAAAAA">=2</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: yak shaved successfully</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290157Z </font><font color="#3465A4">DEBUG</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: yak_events: </font><i>yak</i><font color="#AAAAAA">=2 </font><i>shaved</i><font color="#AAAAAA">=true</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290174Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: </font><i>yaks_shaved</i><font color="#AAAAAA">=2</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290198Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">:</font><b>shave{</b><i>yak</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: hello! I&apos;m gonna shave a yak </font><i>excitement</i><font color="#AAAAAA">=&quot;yay!&quot;</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290222Z </font><font color="#C4A000"> WARN</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">:</font><b>shave{</b><i>yak</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: could not locate yak</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290247Z </font><font color="#3465A4">DEBUG</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: yak_events: </font><i>yak</i><font color="#AAAAAA">=3 </font><i>shaved</i><font color="#AAAAAA">=false</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290268Z </font><font color="#CC0000">ERROR</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: failed to shave yak </font><i>yak</i><font color="#AAAAAA">=3 </font><i>error</i><font color="#AAAAAA">=missing yak </font><i>error.sources</i><font color="#AAAAAA">=[out of space, out of cash]</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290287Z </font><font color="#75507B">TRACE</font> <b>shaving_yaks{</b><i>yaks</i><font color="#AAAAAA">=3</font><b>}</b><font color="#AAAAAA">: fmt::yak_shave: </font><i>yaks_shaved</i><font color="#AAAAAA">=2</font>
-/// <font color="#AAAAAA">2022-02-15T18:40:14.290309Z </font><font color="#4E9A06"> INFO</font> fmt: yak shaving completed. <i>all_yaks_shaved</i><font color="#AAAAAA">=false</font>
-/// </pre>
+/// The full format includes fields from all entered spans.
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct Full;
@@ -390,11 +311,8 @@ pub struct Full;
/// You will usually want to use this as the `FormatEvent` for a `FmtSubscriber`.
///
/// The default logging format, [`Full`] includes all fields in each event and its containing
-/// spans. The [`Compact`] logging format is intended to produce shorter log
-/// lines; it displays each event's fields, along with fields from the current
-/// span context, but other information is abbreviated. The [`Pretty`] logging
-/// format is an extra-verbose, multi-line human-readable logging format
-/// intended for use in development.
+/// spans. The [`Compact`] logging format includes only the fields from the most-recently-entered
+/// span.
#[derive(Debug, Clone)]
pub struct Format<F = Full, T = SystemTime> {
format: F,
@@ -405,8 +323,6 @@ pub struct Format<F = Full, T = SystemTime> {
pub(crate) display_level: bool,
pub(crate) display_thread_id: bool,
pub(crate) display_thread_name: bool,
- pub(crate) display_filename: bool,
- pub(crate) display_line_number: bool,
}
// === impl Writer ===
@@ -583,8 +499,6 @@ impl Default for Format<Full, SystemTime> {
display_level: true,
display_thread_id: false,
display_thread_name: false,
- display_filename: false,
- display_line_number: false,
}
}
}
@@ -603,8 +517,6 @@ impl<F, T> Format<F, T> {
display_level: self.display_level,
display_thread_id: self.display_thread_id,
display_thread_name: self.display_thread_name,
- display_filename: self.display_filename,
- display_line_number: self.display_line_number,
}
}
@@ -642,8 +554,6 @@ impl<F, T> Format<F, T> {
display_level: self.display_level,
display_thread_id: self.display_thread_id,
display_thread_name: self.display_thread_name,
- display_filename: true,
- display_line_number: true,
}
}
@@ -661,6 +571,8 @@ impl<F, T> Format<F, T> {
///
/// - [`Format::flatten_event`] can be used to enable flattening event fields into the root
/// object.
+ ///
+ /// [`Format::flatten_event`]: #method.flatten_event
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub fn json(self) -> Format<Json, T> {
@@ -673,8 +585,6 @@ impl<F, T> Format<F, T> {
display_level: self.display_level,
display_thread_id: self.display_thread_id,
display_thread_name: self.display_thread_name,
- display_filename: self.display_filename,
- display_line_number: self.display_line_number,
}
}
@@ -702,8 +612,6 @@ impl<F, T> Format<F, T> {
display_level: self.display_level,
display_thread_id: self.display_thread_id,
display_thread_name: self.display_thread_name,
- display_filename: self.display_filename,
- display_line_number: self.display_line_number,
}
}
@@ -718,8 +626,6 @@ impl<F, T> Format<F, T> {
display_level: self.display_level,
display_thread_id: self.display_thread_id,
display_thread_name: self.display_thread_name,
- display_filename: self.display_filename,
- display_line_number: self.display_line_number,
}
}
@@ -748,9 +654,9 @@ impl<F, T> Format<F, T> {
}
/// Sets whether or not the [thread ID] of the current thread is displayed
- /// when formatting events.
+ /// when formatting events
///
- /// [thread ID]: std::thread::ThreadId
+ /// [thread ID]: https://doc.rust-lang.org/stable/std/thread/struct.ThreadId.html
pub fn with_thread_ids(self, display_thread_id: bool) -> Format<F, T> {
Format {
display_thread_id,
@@ -759,9 +665,9 @@ impl<F, T> Format<F, T> {
}
/// Sets whether or not the [name] of the current thread is displayed
- /// when formatting events.
+ /// when formatting events
///
- /// [name]: std::thread#naming-threads
+ /// [name]: https://doc.rust-lang.org/stable/std/thread/index.html#naming-threads
pub fn with_thread_names(self, display_thread_name: bool) -> Format<F, T> {
Format {
display_thread_name,
@@ -769,38 +675,6 @@ impl<F, T> Format<F, T> {
}
}
- /// Sets whether or not an event's [source code file path][file] is
- /// displayed.
- ///
- /// [file]: tracing_core::Metadata::file
- pub fn with_file(self, display_filename: bool) -> Format<F, T> {
- Format {
- display_filename,
- ..self
- }
- }
-
- /// Sets whether or not an event's [source code line number][line] is
- /// displayed.
- ///
- /// [line]: tracing_core::Metadata::line
- pub fn with_line_number(self, display_line_number: bool) -> Format<F, T> {
- Format {
- display_line_number,
- ..self
- }
- }
-
- /// Sets whether or not the source code location from which an event
- /// originated is displayed.
- ///
- /// This is equivalent to calling [`Format::with_file`] and
- /// [`Format::with_line_number`] with the same value.
- pub fn with_source_location(self, display_location: bool) -> Self {
- self.with_line_number(display_location)
- .with_file(display_location)
- }
-
#[inline]
fn format_timestamp(&self, writer: &mut Writer<'_>) -> fmt::Result
where
@@ -818,24 +692,14 @@ impl<F, T> Format<F, T> {
if writer.has_ansi_escapes() {
let style = Style::new().dimmed();
write!(writer, "{}", style.prefix())?;
-
- // If getting the timestamp failed, don't bail --- only bail on
- // formatting errors.
- if self.timer.format_time(writer).is_err() {
- writer.write_str("<unknown time>")?;
- }
-
+ self.timer.format_time(writer)?;
write!(writer, "{} ", style.suffix())?;
return Ok(());
}
}
// Otherwise, just format the timestamp without ANSI formatting.
- // If getting the timestamp failed, don't bail --- only bail on
- // formatting errors.
- if self.timer.format_time(writer).is_err() {
- writer.write_str("<unknown time>")?;
- }
+ self.timer.format_time(writer)?;
writer.write_char(' ')
}
}
@@ -850,7 +714,7 @@ impl<T> Format<Json, T> {
/// ```ignore,json
/// {"timestamp":"Feb 20 11:28:15.096","level":"INFO","target":"mycrate", "message":"some message", "key": "value"}
/// ```
- /// See [`Json`][super::format::Json].
+ /// See [`Json`](../format/struct.Json.html).
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub fn flatten_event(mut self, flatten_event: bool) -> Format<Json, T> {
@@ -861,7 +725,7 @@ impl<T> Format<Json, T> {
/// Sets whether or not the formatter will include the current span in
/// formatted events.
///
- /// See [`format::Json`][Json]
+ /// See [`format::Json`](../fmt/format/struct.Json.html)
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub fn with_current_span(mut self, display_current_span: bool) -> Format<Json, T> {
@@ -872,7 +736,7 @@ impl<T> Format<Json, T> {
/// Sets whether or not the formatter will include a list (from root to
/// leaf) of all currently entered spans in formatted events.
///
- /// See [`format::Json`][Json]
+ /// See [`format::Json`](../fmt/format/struct.Json.html)
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub fn with_span_list(mut self, display_span_list: bool) -> Format<Json, T> {
@@ -976,34 +840,6 @@ where
)?;
}
- let line_number = if self.display_line_number {
- meta.line()
- } else {
- None
- };
-
- if self.display_filename {
- if let Some(filename) = meta.file() {
- write!(
- writer,
- "{}{}{}",
- dimmed.paint(filename),
- dimmed.paint(":"),
- if line_number.is_some() { "" } else { " " }
- )?;
- }
- }
-
- if let Some(line_number) = line_number {
- write!(
- writer,
- "{}{}:{} ",
- dimmed.prefix(),
- line_number,
- dimmed.suffix()
- )?;
- }
-
ctx.format_fields(writer.by_ref(), event)?;
writeln!(writer)
}
@@ -1082,49 +918,23 @@ where
};
write!(writer, "{}", fmt_ctx)?;
- let bold = writer.bold();
- let dimmed = writer.dimmed();
-
- let mut needs_space = false;
if self.display_target {
- write!(writer, "{}{}", bold.paint(meta.target()), dimmed.paint(":"))?;
- needs_space = true;
- }
-
- if self.display_filename {
- if let Some(filename) = meta.file() {
- if self.display_target {
- writer.write_char(' ')?;
- }
- write!(writer, "{}{}", bold.paint(filename), dimmed.paint(":"))?;
- needs_space = true;
- }
- }
-
- if self.display_line_number {
- if let Some(line_number) = meta.line() {
- write!(
- writer,
- "{}{}{}{}",
- bold.prefix(),
- line_number,
- bold.suffix(),
- dimmed.paint(":")
- )?;
- needs_space = true;
- }
- }
-
- if needs_space {
- writer.write_char(' ')?;
+ write!(
+ writer,
+ "{}{} ",
+ writer.bold().paint(meta.target()),
+ writer.dimmed().paint(":")
+ )?;
}
ctx.format_fields(writer.by_ref(), event)?;
+ let dimmed = writer.dimmed();
for span in ctx
.event_scope()
.into_iter()
- .flat_map(crate::registry::Scope::from_root)
+ .map(crate::registry::Scope::from_root)
+ .flatten()
{
let exts = span.extensions();
if let Some(fields) = exts.get::<FormattedFields<N>>() {
@@ -1152,6 +962,7 @@ where
/// The default [`FormatFields`] implementation.
///
+/// [`FormatFields`]: trait.FormatFields.html
#[derive(Debug)]
pub struct DefaultFields {
// reserve the ability to add fields to this without causing a breaking
@@ -1173,6 +984,7 @@ pub struct DefaultVisitor<'a> {
impl DefaultFields {
/// Returns a new default [`FormatFields`] implementation.
///
+ /// [`FormatFields`]: trait.FormatFields.html
pub fn new() -> Self {
Self { _private: () }
}
@@ -1389,14 +1201,6 @@ impl Style {
fn paint(&self, d: impl fmt::Display) -> impl fmt::Display {
d
}
-
- fn prefix(&self) -> impl fmt::Display {
- ""
- }
-
- fn suffix(&self) -> impl fmt::Display {
- ""
- }
}
struct FmtThreadName<'a> {
@@ -1562,7 +1366,7 @@ impl<'a, F> fmt::Debug for FieldFnVisitor<'a, F> {
/// Configures what points in the span lifecycle are logged as events.
///
-/// See also [`with_span_events`](super::SubscriberBuilder.html::with_span_events).
+/// See also [`with_span_events`](../struct.SubscriberBuilder.html#method.with_span_events).
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct FmtSpan(u8);
@@ -1724,9 +1528,7 @@ pub(super) mod test {
};
use super::*;
-
- use regex::Regex;
- use std::{fmt, path::Path};
+ use std::fmt;
pub(crate) struct MockTime;
impl FormatTime for MockTime {
@@ -1748,7 +1550,7 @@ pub(super) mod test {
.with_thread_names(false);
#[cfg(feature = "ansi")]
let subscriber = subscriber.with_ansi(false);
- assert_info_hello(subscriber, make_writer, "hello\n")
+ run_test(subscriber, make_writer, "hello\n")
}
fn test_ansi<T>(
@@ -1796,124 +1598,6 @@ pub(super) mod test {
run_test(subscriber, make_writer, expected);
}
- #[test]
- fn with_line_number_and_file_name() {
- let make_writer = MockMakeWriter::default();
- let subscriber = crate::fmt::Subscriber::builder()
- .with_writer(make_writer.clone())
- .with_file(true)
- .with_line_number(true)
- .with_level(false)
- .with_ansi(false)
- .with_timer(MockTime);
-
- let expected = Regex::new(&format!(
- "^fake time tracing_subscriber::fmt::format::test: {}:[0-9]+: hello\n$",
- current_path()
- // if we're on Windows, the path might contain backslashes, which
- // have to be escpaed before compiling the regex.
- .replace('\\', "\\\\")
- ))
- .unwrap();
- let _default = set_default(&subscriber.into());
- tracing::info!("hello");
- let res = make_writer.get_string();
- assert!(expected.is_match(&res));
- }
-
- #[test]
- fn with_line_number() {
- let make_writer = MockMakeWriter::default();
- let subscriber = crate::fmt::Subscriber::builder()
- .with_writer(make_writer.clone())
- .with_line_number(true)
- .with_level(false)
- .with_ansi(false)
- .with_timer(MockTime);
-
- let expected =
- Regex::new("^fake time tracing_subscriber::fmt::format::test: [0-9]+: hello\n$")
- .unwrap();
- let _default = set_default(&subscriber.into());
- tracing::info!("hello");
- let res = make_writer.get_string();
- assert!(expected.is_match(&res));
- }
-
- #[test]
- fn with_filename() {
- let make_writer = MockMakeWriter::default();
- let subscriber = crate::fmt::Subscriber::builder()
- .with_writer(make_writer.clone())
- .with_file(true)
- .with_level(false)
- .with_ansi(false)
- .with_timer(MockTime);
- let expected = &format!(
- "fake time tracing_subscriber::fmt::format::test: {}: hello\n",
- current_path(),
- );
- assert_info_hello(subscriber, make_writer, expected);
- }
-
- #[test]
- fn with_thread_ids() {
- let make_writer = MockMakeWriter::default();
- let subscriber = crate::fmt::Subscriber::builder()
- .with_writer(make_writer.clone())
- .with_thread_ids(true)
- .with_ansi(false)
- .with_timer(MockTime);
- let expected =
- "fake time INFO ThreadId(NUMERIC) tracing_subscriber::fmt::format::test: hello\n";
-
- assert_info_hello_ignore_numeric(subscriber, make_writer, expected);
- }
-
- #[test]
- fn pretty_default() {
- let make_writer = MockMakeWriter::default();
- let subscriber = crate::fmt::Subscriber::builder()
- .pretty()
- .with_writer(make_writer.clone())
- .with_ansi(false)
- .with_timer(MockTime);
- let expected = format!(
- r#" fake time INFO tracing_subscriber::fmt::format::test: hello
- at {}:NUMERIC
-
-"#,
- file!()
- );
-
- assert_info_hello_ignore_numeric(subscriber, make_writer, &expected)
- }
-
- fn assert_info_hello(subscriber: impl Into<Dispatch>, buf: MockMakeWriter, expected: &str) {
- let _default = set_default(&subscriber.into());
- tracing::info!("hello");
- let result = buf.get_string();
-
- assert_eq!(expected, result)
- }
-
- // When numeric characters are used they often form a non-deterministic value as they usually represent things like a thread id or line number.
- // This assert method should be used when non-deterministic numeric characters are present.
- fn assert_info_hello_ignore_numeric(
- subscriber: impl Into<Dispatch>,
- buf: MockMakeWriter,
- expected: &str,
- ) {
- let _default = set_default(&subscriber.into());
- tracing::info!("hello");
-
- let regex = Regex::new("[0-9]+").unwrap();
- let result = buf.get_string();
- let result_cleaned = regex.replace_all(&result, "NUMERIC");
-
- assert_eq!(expected, result_cleaned)
- }
-
fn test_overridden_parents<T>(
expected: &str,
builder: crate::fmt::SubscriberBuilder<DefaultFields, Format<T>>,
@@ -1922,14 +1606,14 @@ pub(super) mod test {
T: Send + Sync + 'static,
{
let make_writer = MockMakeWriter::default();
- let subscriber = builder
+ let collector = builder
.with_writer(make_writer.clone())
.with_level(false)
.with_ansi(false)
.with_timer(MockTime)
.finish();
- with_default(subscriber, || {
+ with_default(collector, || {
let span1 = tracing::info_span!("span1", span = 1);
let span2 = tracing::info_span!(parent: &span1, "span2", span = 2);
tracing::info!(parent: &span2, "hello");
@@ -1975,21 +1659,6 @@ pub(super) mod test {
mod default {
use super::*;
-
- #[test]
- fn with_thread_ids() {
- let make_writer = MockMakeWriter::default();
- let subscriber = crate::fmt::Subscriber::builder()
- .with_writer(make_writer.clone())
- .with_thread_ids(true)
- .with_ansi(false)
- .with_timer(MockTime);
- let expected =
- "fake time INFO ThreadId(NUMERIC) tracing_subscriber::fmt::format::test: hello\n";
-
- assert_info_hello_ignore_numeric(subscriber, make_writer, expected);
- }
-
#[cfg(feature = "ansi")]
#[test]
fn with_ansi_true() {
@@ -2079,26 +1748,6 @@ pub(super) mod test {
}
}
- mod pretty {
- use super::*;
-
- #[test]
- fn pretty_default() {
- let make_writer = MockMakeWriter::default();
- let subscriber = crate::fmt::Subscriber::builder()
- .pretty()
- .with_writer(make_writer.clone())
- .with_ansi(false)
- .with_timer(MockTime);
- let expected = format!(
- " fake time INFO tracing_subscriber::fmt::format::test: hello\n at {}:NUMERIC\n\n",
- file!()
- );
-
- assert_info_hello_ignore_numeric(subscriber, make_writer, &expected)
- }
- }
-
#[test]
fn format_nanos() {
fn fmt(t: u64) -> String {
@@ -2146,16 +1795,4 @@ pub(super) mod test {
assert!(!f.contains(FmtSpan::EXIT));
assert!(f.contains(FmtSpan::CLOSE));
}
-
- /// Returns the test's module path.
- fn current_path() -> String {
- Path::new("tracing-subscriber")
- .join("src")
- .join("fmt")
- .join("format")
- .join("mod.rs")
- .to_str()
- .expect("path must not contain invalid unicode")
- .to_owned()
- }
}
diff --git a/vendor/tracing-subscriber/src/fmt/format/pretty.rs b/vendor/tracing-subscriber-0.3.3/src/fmt/format/pretty.rs
index a50d08ba7..3e47e2d93 100644
--- a/vendor/tracing-subscriber/src/fmt/format/pretty.rs
+++ b/vendor/tracing-subscriber-0.3.3/src/fmt/format/pretty.rs
@@ -17,84 +17,6 @@ use tracing_log::NormalizeEvent;
use ansi_term::{Colour, Style};
/// An excessively pretty, human-readable event formatter.
-///
-/// Unlike the [`Full`], [`Compact`], and [`Json`] formatters, this is a
-/// multi-line output format. Each individual event may output multiple lines of
-/// text.
-///
-/// # Example Output
-///
-/// <pre><font color="#4E9A06"><b>:;</b></font> <font color="#4E9A06">cargo</font> run --example fmt-pretty
-/// <font color="#4E9A06"><b> Finished</b></font> dev [unoptimized + debuginfo] target(s) in 0.08s
-/// <font color="#4E9A06"><b> Running</b></font> `target/debug/examples/fmt-pretty`
-/// 2022-02-15T18:44:24.535324Z <font color="#4E9A06"> INFO</font> <font color="#4E9A06"><b>fmt_pretty</b></font><font color="#4E9A06">: preparing to shave yaks, </font><font color="#4E9A06"><b>number_of_yaks</b></font><font color="#4E9A06">: 3</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt-pretty.rs:16 <font color="#AAAAAA"><i>on</i></font> main
-///
-/// 2022-02-15T18:44:24.535403Z <font color="#4E9A06"> INFO</font> <font color="#4E9A06"><b>fmt_pretty::yak_shave</b></font><font color="#4E9A06">: shaving yaks</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:41 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535442Z <font color="#75507B">TRACE</font> <font color="#75507B"><b>fmt_pretty::yak_shave</b></font><font color="#75507B">: hello! I&apos;m gonna shave a yak, </font><font color="#75507B"><b>excitement</b></font><font color="#75507B">: &quot;yay!&quot;</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:16 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shave</b> <font color="#AAAAAA"><i>with</i></font> <b>yak</b>: 1
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535469Z <font color="#75507B">TRACE</font> <font color="#75507B"><b>fmt_pretty::yak_shave</b></font><font color="#75507B">: yak shaved successfully</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:25 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shave</b> <font color="#AAAAAA"><i>with</i></font> <b>yak</b>: 1
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535502Z <font color="#3465A4">DEBUG</font> <font color="#3465A4"><b>yak_events</b></font><font color="#3465A4">: </font><font color="#3465A4"><b>yak</b></font><font color="#3465A4">: 1, </font><font color="#3465A4"><b>shaved</b></font><font color="#3465A4">: true</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:46 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535524Z <font color="#75507B">TRACE</font> <font color="#75507B"><b>fmt_pretty::yak_shave</b></font><font color="#75507B">: </font><font color="#75507B"><b>yaks_shaved</b></font><font color="#75507B">: 1</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:55 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535551Z <font color="#75507B">TRACE</font> <font color="#75507B"><b>fmt_pretty::yak_shave</b></font><font color="#75507B">: hello! I&apos;m gonna shave a yak, </font><font color="#75507B"><b>excitement</b></font><font color="#75507B">: &quot;yay!&quot;</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:16 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shave</b> <font color="#AAAAAA"><i>with</i></font> <b>yak</b>: 2
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535573Z <font color="#75507B">TRACE</font> <font color="#75507B"><b>fmt_pretty::yak_shave</b></font><font color="#75507B">: yak shaved successfully</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:25 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shave</b> <font color="#AAAAAA"><i>with</i></font> <b>yak</b>: 2
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535600Z <font color="#3465A4">DEBUG</font> <font color="#3465A4"><b>yak_events</b></font><font color="#3465A4">: </font><font color="#3465A4"><b>yak</b></font><font color="#3465A4">: 2, </font><font color="#3465A4"><b>shaved</b></font><font color="#3465A4">: true</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:46 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535618Z <font color="#75507B">TRACE</font> <font color="#75507B"><b>fmt_pretty::yak_shave</b></font><font color="#75507B">: </font><font color="#75507B"><b>yaks_shaved</b></font><font color="#75507B">: 2</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:55 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535644Z <font color="#75507B">TRACE</font> <font color="#75507B"><b>fmt_pretty::yak_shave</b></font><font color="#75507B">: hello! I&apos;m gonna shave a yak, </font><font color="#75507B"><b>excitement</b></font><font color="#75507B">: &quot;yay!&quot;</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:16 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shave</b> <font color="#AAAAAA"><i>with</i></font> <b>yak</b>: 3
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535670Z <font color="#C4A000"> WARN</font> <font color="#C4A000"><b>fmt_pretty::yak_shave</b></font><font color="#C4A000">: could not locate yak</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:18 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shave</b> <font color="#AAAAAA"><i>with</i></font> <b>yak</b>: 3
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535698Z <font color="#3465A4">DEBUG</font> <font color="#3465A4"><b>yak_events</b></font><font color="#3465A4">: </font><font color="#3465A4"><b>yak</b></font><font color="#3465A4">: 3, </font><font color="#3465A4"><b>shaved</b></font><font color="#3465A4">: false</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:46 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535720Z <font color="#CC0000">ERROR</font> <font color="#CC0000"><b>fmt_pretty::yak_shave</b></font><font color="#CC0000">: failed to shave yak, </font><font color="#CC0000"><b>yak</b></font><font color="#CC0000">: 3, </font><font color="#CC0000"><b>error</b></font><font color="#CC0000">: missing yak, </font><font color="#CC0000"><b>error.sources</b></font><font color="#CC0000">: [out of space, out of cash]</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:51 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535742Z <font color="#75507B">TRACE</font> <font color="#75507B"><b>fmt_pretty::yak_shave</b></font><font color="#75507B">: </font><font color="#75507B"><b>yaks_shaved</b></font><font color="#75507B">: 2</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt/yak_shave.rs:55 <font color="#AAAAAA"><i>on</i></font> main
-/// <font color="#AAAAAA"><i>in</i></font> fmt_pretty::yak_shave::<b>shaving_yaks</b> <font color="#AAAAAA"><i>with</i></font> <b>yaks</b>: 3
-///
-/// 2022-02-15T18:44:24.535765Z <font color="#4E9A06"> INFO</font> <font color="#4E9A06"><b>fmt_pretty</b></font><font color="#4E9A06">: yak shaving completed, </font><font color="#4E9A06"><b>all_yaks_shaved</b></font><font color="#4E9A06">: false</font>
-/// <font color="#AAAAAA"><i>at</i></font> examples/examples/fmt-pretty.rs:19 <font color="#AAAAAA"><i>on</i></font> main
-/// </pre>
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Pretty {
display_location: bool,
@@ -154,10 +76,6 @@ impl Pretty {
/// Sets whether the event's source code location is displayed.
///
/// This defaults to `true`.
- #[deprecated(
- since = "0.3.6",
- note = "all formatters now support configurable source locations. Use `Format::with_source_location` instead."
- )]
pub fn with_source_location(self, display_location: bool) -> Self {
Self {
display_location,
@@ -166,6 +84,17 @@ impl Pretty {
}
}
+impl<T> Format<Pretty, T> {
+ /// Sets whether or not the source code location from which an event
+ /// originated is displayed.
+ ///
+ /// This defaults to `true`.
+ pub fn with_source_location(mut self, display_location: bool) -> Self {
+ self.format = self.format.with_source_location(display_location);
+ self
+ }
+}
+
impl<C, N, T> FormatEvent<C, N> for Format<Pretty, T>
where
C: Subscriber + for<'a> LookupSpan<'a>,
@@ -218,37 +147,12 @@ where
};
write!(
writer,
- "{}{}{}:",
+ "{}{}{}: ",
target_style.prefix(),
meta.target(),
target_style.infix(style)
)?;
}
- let line_number = if self.display_line_number {
- meta.line()
- } else {
- None
- };
-
- // If the file name is disabled, format the line number right after the
- // target. Otherwise, if we also display the file, it'll go on a
- // separate line.
- if let (Some(line_number), false, true) = (
- line_number,
- self.display_filename,
- self.format.display_location,
- ) {
- write!(
- writer,
- "{}{}{}:",
- style.prefix(),
- line_number,
- style.infix(style)
- )?;
- }
-
- writer.write_char(' ')?;
-
let mut v = PrettyVisitor::new(writer.by_ref(), true).with_style(style);
event.record(&mut v);
v.finish()?;
@@ -260,21 +164,20 @@ where
Style::new()
};
let thread = self.display_thread_name || self.display_thread_id;
-
- if let (Some(file), true, true) = (
- meta.file(),
- self.format.display_location,
- self.display_filename,
- ) {
- write!(writer, " {} {}", dimmed.paint("at"), file,)?;
-
- if let Some(line) = line_number {
- write!(writer, ":{}", line)?;
- }
- writer.write_char(if thread { ' ' } else { '\n' })?;
+ if let (true, Some(file), Some(line)) =
+ (self.format.display_location, meta.file(), meta.line())
+ {
+ write!(
+ writer,
+ " {} {}:{}{}",
+ dimmed.paint("at"),
+ file,
+ line,
+ dimmed.paint(if thread { " " } else { "\n" })
+ )?;
} else if thread {
write!(writer, " ")?;
- };
+ }
if thread {
write!(writer, "{} ", dimmed.paint("on"))?;
@@ -283,12 +186,13 @@ where
if let Some(name) = thread.name() {
write!(writer, "{}", name)?;
if self.display_thread_id {
- writer.write_char(' ')?;
+ write!(writer, " ({:?})", thread.id())?;
}
+ } else if !self.display_thread_id {
+ write!(writer, " {:?}", thread.id())?;
}
- }
- if self.display_thread_id {
- write!(writer, "{:?}", thread.id())?;
+ } else if self.display_thread_id {
+ write!(writer, " {:?}", thread.id())?;
}
writer.write_char('\n')?;
}
@@ -336,7 +240,7 @@ where
impl<'writer> FormatFields<'writer> for Pretty {
fn format_fields<R: RecordFields>(&self, writer: Writer<'writer>, fields: R) -> fmt::Result {
- let mut v = PrettyVisitor::new(writer, true);
+ let mut v = PrettyVisitor::new(writer, false);
fields.record(&mut v);
v.finish()
}