Skip to content

Commit

Permalink
Renamed
Browse files Browse the repository at this point in the history
A crate called tracing-json already exists
  • Loading branch information
jjtt committed Jul 25, 2023
1 parent f5ee345 commit d65d4df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "tracing_json"
name = "tracing_json_span_fields"
version = "0.1.0"
edition = "2021"
license = "MIT"
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ implementation treats spans as a way to provide context and adds all fields from
```rust
use tracing::{info, info_span};
use tracing_subscriber::prelude::*;
use tracing_json::JsonLayer;
use tracing_json_span_fields::JsonLayer;
tracing_subscriber::registry().with(JsonLayer::pretty()).init();
let _span = info_span!("A span", span_field = 42).entered();
info!(logged_message_field = "value", "Logged message");
Expand All @@ -30,7 +30,7 @@ Will produce the following output
use time::macros::format_description;
use tracing::{error, info_span};
use tracing_subscriber::prelude::*;
use tracing_json::JsonLayer;
use tracing_json_span_fields::JsonLayer;
let timestamp_format = format_description!("[hour]:[minute]:[second].[subsecond digits:1]");
tracing_subscriber::registry().with(JsonLayer::default().with_timestamp_format(timestamp_format)).init();
let _span = info_span!("A span", span_field = 42).entered();
Expand All @@ -43,3 +43,7 @@ Will produce the following output

## Thanks
* <https://burgers.io/custom-logging-in-rust-using-tracing>

## See also

* <https://github.com/vertexclique/tracing-json> is a very similar crate, but lacking documentation
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! ```
//! use tracing::{info, info_span};
//! use tracing_subscriber::prelude::*;
//! use tracing_json::JsonLayer;
//! use tracing_json_span_fields::JsonLayer;
//! tracing_subscriber::registry().with(JsonLayer::pretty()).init();
//! let _span = info_span!("A span", span_field = 42).entered();
//! info!(logged_message_field = "value", "Logged message");
Expand All @@ -33,7 +33,7 @@
//! use time::macros::format_description;
//! use tracing::{error, info_span};
//! use tracing_subscriber::prelude::*;
//! use tracing_json::JsonLayer;
//! use tracing_json_span_fields::JsonLayer;
//! let timestamp_format = format_description!("[hour]:[minute]:[second].[subsecond digits:1]");
//! tracing_subscriber::registry().with(JsonLayer::default().with_timestamp_format(timestamp_format)).init();
//! let _span = info_span!("A span", span_field = 42).entered();
Expand Down Expand Up @@ -375,7 +375,7 @@ mod tests {

assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "FOOBAR",
"field_top": 0,
Expand All @@ -387,7 +387,7 @@ mod tests {
);
assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "ERROR",
"message": "BAZ",
"field_top": 0,
Expand Down Expand Up @@ -419,7 +419,7 @@ mod tests {

assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "FOOBAR",
"field_top": 0,
Expand Down Expand Up @@ -453,7 +453,7 @@ mod tests {

assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "FOOBAR",
"field_overwrite": 1,
Expand Down Expand Up @@ -486,7 +486,7 @@ mod tests {

assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "FOOBAR",
"field_overwrite": "from event"
Expand Down Expand Up @@ -519,7 +519,7 @@ mod tests {

assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "ONE",
"field_top": 0,
Expand All @@ -531,7 +531,7 @@ mod tests {
);
assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "TWO",
"field_top": 0,
Expand Down Expand Up @@ -566,7 +566,7 @@ mod tests {

assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "FOOBAR",
"event_field": 1.1,
Expand Down Expand Up @@ -601,7 +601,7 @@ mod tests {

assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "FOOBAR",
"event_field": 1.1,
Expand Down Expand Up @@ -632,7 +632,7 @@ mod tests {

assert_json_timestamp_name(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "FOOBAR",
"event_field": 1.1,
Expand Down Expand Up @@ -667,7 +667,7 @@ mod tests {

assert_json_timestamp_name_with_format(
serde_json::json!({
"target": "tracing_json::tests",
"target": "tracing_json_span_fields::tests",
"log_level": "INFO",
"message": "FOOBAR",
"event_field": 1.1,
Expand Down

0 comments on commit d65d4df

Please sign in to comment.