mirror of
https://github.com/gechandesu/structlog.git
synced 2026-04-15 05:43:19 +03:00
* Add os.File.flush() call to fix writing log into files. * Add comma as TextHandler fields separator. * Add struct_adapter() * Add field() generic function to creating Field instances. * Add new write_to_file.v example. * Rename Record.field() to Record.add()
22 lines
477 B
V
22 lines
477 B
V
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().add('random_string', rand.string(100)).send()
|
|
log.info().add('answer', 42).add('computed_by', 'Deep Thought').send()
|
|
log.error().message('this line contains error').error(error('oops')).send()
|
|
}
|