-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a visitor pattern instead of
FormattedFields
(#12)
This changes a lot of the insides of the crate, but the API is mostly the same. While the visitor pattern is a bit more verbose, it's also more flexible and allows for more customization in the future.
- Loading branch information
1 parent
b1dd04d
commit ca110b6
Showing
14 changed files
with
386 additions
and
681 deletions.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# rustup install nightly | ||
group_imports = "StdExternalCrate" | ||
format_code_in_doc_comments = true |
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
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
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,23 +1,25 @@ | ||
use tracing_subscriber::prelude::*; | ||
|
||
fn main() { | ||
tracing_subscriber::registry() | ||
.with( | ||
tracing_ndjson::builder() | ||
.with_level_name("severity") | ||
.with_message_name("msg") | ||
.with_timestamp_name("ts") | ||
.with_timestamp_format(tracing_ndjson::TimestampFormat::Unix) | ||
.layer(), | ||
) | ||
.init(); | ||
let subscriber = tracing_subscriber::registry().with( | ||
tracing_ndjson::builder() | ||
.with_level_name("severity") | ||
.with_level_value_casing(tracing_ndjson::Casing::Uppercase) | ||
.with_timestamp_name("ts") | ||
.with_timestamp_format(tracing_ndjson::TimestampFormat::UnixMillis) | ||
.with_message_name("msg") | ||
.with_line_numbers(true) | ||
.with_file_names(true) | ||
.layer(), | ||
); | ||
|
||
tracing::subscriber::set_global_default(subscriber).unwrap(); | ||
|
||
tracing::info!(life = 42, "Hello, world!"); | ||
// {"level":"info","timestamp":"2023-10-08T03:30:52Z","target":"default","message":"Hello, world!"} | ||
// {"life":42,"msg":"Hello, world!","target":"customize","ts":1697836630814,"file":"examples/customize.rs","line":17,"severity":"INFO"} | ||
|
||
let span = tracing::info_span!("hello", "request.uri" = "https://example.com"); | ||
span.in_scope(|| { | ||
tracing::info!("Hello, world!"); | ||
// {"level":"info","timestamp":"2023-10-08T03:34:33Z","target":"defaults","message":"Hello, world!","request.uri":"https://example.com"} | ||
// {"severity":"INFO","target":"customize","file":"examples/customize.rs","msg":"Hello, world!","ts":1697836630814,"line":22,"request.uri":"https://example.com"} | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use tracing_subscriber::prelude::*; | ||
fn main() { | ||
let subscriber = tracing_subscriber::registry().with(tracing_ndjson::layer()); | ||
|
||
tracing::subscriber::set_global_default(subscriber).unwrap(); | ||
|
||
tracing::info!(life = 42, "Hello, world!"); | ||
// {"level":"info","target":"default","life":42,"timestamp":"2023-10-20T21:17:49Z","message":"Hello, world!"} | ||
|
||
let span = tracing::info_span!("hello", "request.uri" = "https://example.com"); | ||
span.in_scope(|| { | ||
tracing::info!("Hello, world!"); | ||
// {"message":"Hello, world!","request.uri":"https://example.com","level":"info","target":"default","timestamp":"2023-10-20T21:17:49Z"} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.