forked from LukeMathWalker/tracing-bunyan-formatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
valuable.rs
58 lines (51 loc) · 1.32 KB
/
valuable.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
use tracing_subscriber::{layer::SubscriberExt, Registry};
use valuable::Valuable;
#[derive(Valuable)]
struct ValuableStruct {
a: u64,
b: String,
c: ValuableEnum,
}
#[derive(Valuable)]
#[allow(dead_code)]
enum ValuableEnum {
A,
B(u64),
C(String),
}
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let formatting_layer = BunyanFormattingLayer::new("examples_valuable".into(), std::io::stdout);
let subscriber = Registry::default()
.with(JsonStorageLayer)
.with(formatting_layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
let s = ValuableStruct {
a: 17,
b: "foo".to_string(),
c: ValuableEnum::B(26),
};
tracing::info!(s = s.as_value(), "Test event");
// Output example pretty printed:
//
// {
// "v": 0,
// "name": "examples_valuable",
// "msg": "Test event",
// "level": 30,
// "hostname": "foo",
// "pid": 26071,
// "time": "2023-03-29T18:34:38.445454908Z",
// "target": "valuable",
// "line": 36,
// "file": "examples/valuable.rs",
// "s": {
// "a": 17,
// "b": "foo",
// "c": {
// "B": 26
// }
// }
// }
Ok(())
}