mirror of
https://github.com/gechandesu/structlog.git
synced 2026-01-23 16:04:14 +03:00
init
This commit is contained in:
21
examples/json_log.v
Normal file
21
examples/json_log.v
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
import rand
|
||||
import structlog
|
||||
|
||||
fn main() {
|
||||
// Initialize logger with JSONHandler.
|
||||
log := structlog.new(
|
||||
level: .trace
|
||||
handler: structlog.JSONHandler{
|
||||
writer: os.stdout()
|
||||
}
|
||||
)
|
||||
defer {
|
||||
log.close()
|
||||
}
|
||||
|
||||
log.info().message('Hello, World!').send()
|
||||
log.info().field('random_string', rand.string(5)).send()
|
||||
log.info().field('answer', 42).field('computed_by', 'Deep Thought').send()
|
||||
log.error().message('this line contains error').error(error('oops')).send()
|
||||
}
|
||||
Reference in New Issue
Block a user