From 0063eca1775b7928b45792395bec3c6e4cba00a0 Mon Sep 17 00:00:00 2001 From: Naaman Date: Sun, 10 Jul 2022 10:38:51 -0600 Subject: [PATCH] feat(formatting): add parsing of a json object --- Cargo.toml | 2 +- src/formatting.rs | 20 ++++++++++---------- src/storage.rs | 6 ++++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 27ce2a2..6761c70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tracing_sprout" -version = "0.1.0-alpha.5" +version = "0.1.0-alpha.6" authors = ["Naaman Curtis "] edition = "2018" description = "A tokio-rs/tracing structured JSON formatting layer for the fledgling logger" diff --git a/src/formatting.rs b/src/formatting.rs index ed1c0f0..54167ac 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -102,7 +102,7 @@ where let _ = self.emit(serialized); } } else { - eprintln!("[SPROUT]: Expected to find Span ID when creating a new span. \n\tThis is likely a bug"); + tracing::error!(target: "sprout", "Expected to find Span ID when creating a new span. This is likely a bug"); } } @@ -112,10 +112,10 @@ where if let Some(visitor) = extensions.get_mut::() { values.record(visitor); } else { - eprintln!("[SPROUT]: Expected to find Sprout Storage located in the span when recording new attributes.\n\tThis is likely a bug"); + tracing::error!(target: "sprout", "Expected to find Sprout Storage located in the span when recording new attributes. This is likely a bug"); } } else { - eprintln!("[SPROUT]: Expected to find Span ID when recording span attributes.\n\tThis is likely a bug"); + tracing::error!(target: "sprout","Expected to find Span ID when recording span attributes. This is likely a bug"); } } @@ -125,11 +125,11 @@ where if let Some(visitor) = extensions.get_mut::() { visitor.entered_at = Some(Instant::now()); } else { - eprintln!("[SPROUT]: Expected to find Sprout Storage located in the span when entering it.\n\tThis is likely a bug"); + tracing::error!(target: "sprout", "Expected to find Sprout Storage located in the span when entering it. This is likely a bug"); } } else { - eprintln!( - "[SPROUT]: Expected to find Span ID when entering span.\n\tThis is likely a bug" + tracing::error!(target: "sprout", + "Expected to find Span ID when entering span. This is likely a bug" ); } } @@ -148,8 +148,8 @@ where if let Ok(bytes) = serialize_span(visitor.attributes, metadata, Type::Event) { let _ = self.emit(bytes); } else { - eprintln!( - "[SPROUT]: Was unable to write event bytes to the writer.\n\tThis is likely a bug" + tracing::error!(target: "sprout", + "Was unable to write event bytes to the writer. This is likely a bug" ); } } @@ -171,8 +171,8 @@ where } }; } else { - eprintln!( - "[SPROUT]: Expected to find Span ID when closing span.\n\tThis is likely a bug" + tracing::error!(target: "sprout", + "Expected to find Span ID when closing span. This is likely a bug" ); } } diff --git a/src/storage.rs b/src/storage.rs index 906ab18..36e6967 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -89,9 +89,11 @@ impl Visit for SproutStorage { } name => { let val = format!("{:?}", value); - let val = if val.starts_with('[') && val.ends_with(']') { + let val = if (val.starts_with('[') && val.ends_with(']')) + || (val.starts_with('{') && val.ends_with('}')) + { match json::parse(&val) { - Ok(arr) => arr, + Ok(o) => o, Err(_) => val.into(), } } else {