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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
use crateTraceon;
pub use crate;
pub use SecondsFormat;
use DefaultGuard;
pub use ;
/** Returns a builder that can be configured before being turned on, or used as a layer for a subscriber.
```
use traceon::{Case, JoinFields, LevelFormat, SecondsFormat, SpanFormat, TimeFormat, TimeZone, info};
traceon::builder()
// Add field with source code filename and line number e.g. src/main.rs:10
.file()
// Add field with target and module path e.g. mybinary::mymodule::submodule
.module()
// Turn off field with joined span name where the event occured e.g. parentspan::childspan
.span(SpanFormat::None)
// If the time is recorded in local system timezone or UTC
.timezone(TimeZone::UTC)
// Change the formatting of the time to RFC3339 with Seconds and Zulu
.time(TimeFormat::RFC3339Options(SecondsFormat::Secs, true))
// Change the casing of all the key names e.g. `camelCase` to `snake_case`
.case(Case::Snake)
// The characters used to concatenate field values that repeat in nested spans. Defaults to overwrite.
.join_fields(JoinFields::All("::"))
// Turn on json formatting instead of pretty output
.json()
// Change level value formatting to numbers for easier filtering
// trace: 10
// debug: 20
// info: 30
// warn: 40
// error: 50
.level(LevelFormat::Number)
// Put anything that implements Write here to redirect output
.writer(std::io::stderr())
// This will activate it globally on all threads!
.on();
info!("a simple message");
```
json output:
```json
{
"timestamp": "2023-01-01T12:58:49Z",
"level": 30,
"module": "builder",
"file": "examples/builder.rs:32",
"message": "a simple message"
}
```
*/
/**
Turns on the pretty defaults which is local time with no date, where all the span fields are new indented lines, activating it globally on all threads.
# Panics
Will panic if a global default is already set
# Examples
```
traceon::json();
traceon::info!("a json message");
```
output prettified:
```json
{
"time": "2023-01-02T04:46:12.715798+00:00",
"level": "INFO",
"message": "a json message"
}
```
*/
/**
Turn on pretty defaults for the local thread returning a guard, when the guard is dropped the layers will be unsubscribed.
# Examples
Example of using two subscribers on the same thread, second event loses field from first span
```
use traceon::{info, info_span};
let _guard = traceon::on_thread();
let _span = info_span!("span_with_field", field = "temp", "cool").entered();
info!("first subscriber");
let _guard = traceon::json_thread();
let _span = info_span!("span_with_no_field").entered();
info!("second subscriber")
```
output:
```text
11:58:50 INFO first subscriber
field: temp
span: span_with_field
```
```json
{
"time": "2023-01-02T04:59:00.841691+00:00",
"level": "INFO",
"message": "second subscriber",
"span": "span_with_no_field"
}
```
*/
/**
Turns on the json defaults which is one line of flattened json per event with RFC3339 UTC time, activating it globally on all threads.
# Panics
Will panic if a global default is already set
# Examples
```
traceon::json();
traceon::info!("a json message");
```
output prettified:
```json
{
"time": "2023-01-02T04:46:12.715798+00:00",
"level": "INFO",
"message": "a json message"
}
```
*/
/**
Turn on json defaults for the local thread returning a guard, when the guard is dropped the layers will be unsubscribed.
# Examples
Example of using two subscribers on the same thread, second event loses field from first span
```
use traceon::{info, info_span};
let _guard = traceon::on_thread();
let _span = info_span!("span_with_field", field = "temp", "cool").entered();
info!("first subscriber");
let _guard = traceon::json_thread();
let _span = info_span!("span_with_no_field").entered();
info!("second subscriber")
```
output:
```text
11:58:50 INFO first subscriber
field: temp
span: span_with_field
{
"time": "2023-01-02T04:59:00.841691+00:00",
"level": "INFO",
"message": "second subscriber",
"span": "span_with_no_field"
}
```
*/