-
Notifications
You must be signed in to change notification settings - Fork 747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subscriber: "implementing FormatEvent" docs #1727
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9ec93d6
subscriber: "implementing `FormatEvent`" docs
hawkw a7538cb
subscriber: fix broken docs link
hawkw bb541c5
actually, put it in the trait docs
hawkw c4ac523
fix links
hawkw c872c31
Update tracing-subscriber/src/fmt/format/mod.rs
hawkw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
//! A Collector for formatting and logging `tracing` data. | ||
//! | ||
//! ## Overview | ||
//! # Overview | ||
//! | ||
//! [`tracing`] is a framework for instrumenting Rust programs with context-aware, | ||
//! structured, event-based diagnostic information. This crate provides an | ||
//! implementation of the [`Collect`] trait that records `tracing`'s `Event`s | ||
//! and `Span`s by formatting them as text and logging them to stdout. | ||
//! | ||
//! ## Usage | ||
//! # Usage | ||
//! | ||
//! First, add this to your `Cargo.toml` file: | ||
//! | ||
|
@@ -43,12 +43,12 @@ | |
//! **Note**: This should **not** be called by libraries. Libraries should use | ||
//! [`tracing`] to publish `tracing` `Event`s. | ||
//! | ||
//! ## Configuration | ||
//! # Configuration | ||
//! | ||
//! You can configure a collector instead of using the defaults with | ||
//! the following functions: | ||
//! | ||
//! ### Collector | ||
//! ## Collector | ||
//! | ||
//! The [`FmtCollector`] formats and records `tracing` events as line-oriented logs. | ||
//! You can create one by calling: | ||
|
@@ -62,7 +62,7 @@ | |
//! The configuration methods for [`FmtCollector`] can be found in | ||
//! [`fmtBuilder`]. | ||
//! | ||
//! ### Formatters | ||
//! ## Formatters | ||
//! | ||
//! The output format used by the subscriber and collector in this module is | ||
//! represented by implementing the [`FormatEvent`] trait, and can be | ||
|
@@ -223,7 +223,44 @@ | |
//! {"timestamp":"Oct 24 13:00:00.875","level":"INFO","fields":{"message":"yak shaving completed","all_yaks_shaved":false},"target":"fmt_json"} | ||
//! </pre> | ||
//! | ||
//! ### Filters | ||
//! ### Customizing Formatters | ||
//! | ||
//! The formatting of log lines for spans and events is controlled by two | ||
//! traits, [`FormatEvent`] and [`FormatFields`]. The [`FormatEvent`] trait | ||
//! determines the overall formatting of the log line, such as what information | ||
//! from the event's metadata and span context is included and in what order. | ||
//! The [`FormatFields`] trait determines how fields — both the event's | ||
//! fields and fields on spans — are formatted. | ||
Comment on lines
+232
to
+233
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i can't remember the hotkey for typing a literal em dash on my keyboard... |
||
//! | ||
//! The [`fmt::format`] module provides several types which implement these traits, | ||
//! many of which expose additional configuration options to customize their | ||
//! output. The [`format::Format`] type implements common configuration used by | ||
//! all the formatters provided in this crate, and can be used as a builder to | ||
//! set specific formatting settings. For example: | ||
//! | ||
//! ``` | ||
//! use tracing_subscriber::fmt; | ||
//! | ||
//! // Configure a custom event formatter | ||
//! let format = fmt::format() | ||
//! .with_level(false) // don't include levels in formatted output | ||
//! .with_target(false) // don't include targets | ||
//! .with_thread_ids(true) // include the thread ID of the current thread | ||
//! .with_thread_names(true) // include the name of the current thread | ||
//! .compact(); // use the `Compact` formatting style. | ||
//! | ||
//! // Create a `fmt` collector that uses our custom event format, and set it | ||
//! // as the default. | ||
//! tracing_subscriber::fmt() | ||
//! .event_format(format) | ||
//! .init(); | ||
//! ``` | ||
//! | ||
//! However, if a specific output format is needed, other crates can | ||
//! also implement [`FormatEvent`] and [`FormatFields`]. See those traits' | ||
//! documentation for details on how to implement them. | ||
//! | ||
//! ## Filters | ||
//! | ||
//! If you want to filter the `tracing` `Events` based on environment | ||
//! variables, you can use the [`EnvFilter`] as follows: | ||
|
@@ -257,7 +294,7 @@ | |
//! // collector multiple times | ||
//! ``` | ||
//! | ||
//! ### Composing Subscribers | ||
//! ## Composing Subscribers | ||
//! | ||
//! Composing an [`EnvFilter`] `Subscribe` and a [format `Subscribe`](super::fmt::Subscriber): | ||
//! | ||
|
@@ -283,9 +320,9 @@ | |
//! [`filter`]: super::filter | ||
//! [`fmtBuilder`]: CollectorBuilder | ||
//! [`FmtCollector`]: Collector | ||
//! [`Collect`]: | ||
//! https://docs.rs/tracing/latest/tracing/trait.Collect.html | ||
//! [`Collect`]: https://docs.rs/tracing/latest/tracing/trait.Collect.html | ||
//! [`tracing`]: https://crates.io/crates/tracing | ||
//! [`fmt::format`]: mod@crate::fmt::format | ||
use std::{any::TypeId, error::Error, io, ptr::NonNull}; | ||
use tracing_core::{collect::Interest, span, Event, Metadata}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, that's a good name