Skip to content

Commit

Permalink
feat(formatting): add parsing of a json object
Browse files Browse the repository at this point in the history
  • Loading branch information
naamancurtis committed Jul 10, 2022
1 parent ad62c22 commit 0063eca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracing_sprout"
version = "0.1.0-alpha.5"
version = "0.1.0-alpha.6"
authors = ["Naaman Curtis <[email protected]>"]
edition = "2018"
description = "A tokio-rs/tracing structured JSON formatting layer for the fledgling logger"
Expand Down
20 changes: 10 additions & 10 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand All @@ -112,10 +112,10 @@ where
if let Some(visitor) = extensions.get_mut::<SproutStorage>() {
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");
}
}

Expand All @@ -125,11 +125,11 @@ where
if let Some(visitor) = extensions.get_mut::<SproutStorage>() {
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"
);
}
}
Expand All @@ -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"
);
}
}
Expand All @@ -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"
);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0063eca

Please sign in to comment.