Files
structlog/examples/write_to_file.v
ge b423c161af all: various improvements
* 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()
2026-03-28 18:23:57 +03:00

27 lines
570 B
V

import os
import structlog
fn main() {
// Open a file in append mode. If file does not exists it will be created.
log_path := os.join_path_single(os.temp_dir(), 'example_log')
log_file := os.open_file(log_path, 'a+') or {
eprintln('Error: cound not open log file ${log_path}: ${err}')
exit(1)
}
eprintln('Log file location: ${log_path}')
// Initialize logger with os.File as writer.
log := structlog.new(
handler: structlog.TextHandler{
color: false
writer: log_file
}
)
defer {
log.close()
}
log.info().message('Hello, World!').send()
}