-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.v
More file actions
27 lines (23 loc) · 977 Bytes
/
basic.v
File metadata and controls
27 lines (23 loc) · 977 Bytes
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
import rand
import structlog
fn main() {
// Initialize logger with default configuratuion.
log := structlog.new()
defer {
// Since processing and writing the log is done in a separate thread,
// we need to wait for it to complete before exiting the program.
log.close()
}
// Write some logs.
//
// Note the call chain. First, the info() call creates a empty `structlog.Record`
// object with `info` log level. The next message() call adds a message field with
// the specified text to the record. The final send() call sends the record to the
// record handler (TextHandler by default) which writes log to stardard output.
log.info().message('Hello, World!').send()
// You can set your own named fields.
log.info().add('random_string', rand.string(100)).send()
log.info().add('answer', 42).add('computed_by', 'Deep Thought').send()
// Errors can be passed to logger as is.
log.error().message('this line contains error').error(error('oops')).send()
}