mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
📝 Refresh runnable examples
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
async fn main {
|
||||
let config = @lib_async.parse_async_logger_build_config_text(
|
||||
"{\"logger\":{\"min_level\":\"info\",\"target\":\"async.demo\",\"timestamp\":true,\"sink\":{\"kind\":\"text_console\",\"text_formatter\":{\"show_timestamp\":false,\"separator\":\" | \"}}},\"async_config\":{\"max_pending\":2,\"overflow\":\"DropOldest\"}}",
|
||||
) catch {
|
||||
let raw = "{\"logger\":{\"min_level\":\"info\",\"target\":\"async.demo\",\"timestamp\":true,\"sink\":{\"kind\":\"text_console\",\"text_formatter\":{\"show_timestamp\":false,\"separator\":\" | \"}}},\"async_config\":{\"max_pending\":2,\"overflow\":\"DropOldest\",\"max_batch\":4,\"linger_ms\":5,\"flush\":\"Batch\"}}"
|
||||
let config = @lib_async.parse_async_logger_build_config_text(raw) catch {
|
||||
err => {
|
||||
ignore(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
println(@lib_async.stringify_async_logger_build_config(config, pretty=true))
|
||||
|
||||
let logger = @lib_async.build_async_logger(config)
|
||||
.with_context_fields([@lib.field("service", "bitlogger")])
|
||||
@@ -20,6 +20,7 @@ async fn main {
|
||||
group.spawn_bg(allow_failure=true, () => logger.run())
|
||||
logger.info("one", fields=[@lib.field("token", "secret")])
|
||||
logger.child("worker").info("two")
|
||||
logger.child("worker").info("three", fields=[@lib.field("batch", "yes")])
|
||||
logger.with_target("skip.demo").info("three")
|
||||
logger.shutdown()
|
||||
})
|
||||
|
||||
@@ -142,4 +142,45 @@ fn main {
|
||||
}
|
||||
config_logger.info("configured from json")
|
||||
ignore(config_logger.flush())
|
||||
|
||||
let queue_config = @lib.QueueConfig::new(4, overflow=@lib.QueueOverflowPolicy::DropOldest)
|
||||
println(@lib.stringify_queue_config(queue_config))
|
||||
|
||||
let formatter_config = @lib.TextFormatterConfig::new(
|
||||
show_timestamp=false,
|
||||
separator=" | ",
|
||||
field_separator=",",
|
||||
template="[{level}] {target} {message} :: {fields}",
|
||||
)
|
||||
println(@lib.stringify_text_formatter_config(formatter_config))
|
||||
|
||||
let sink_config = @lib.SinkConfig::new(
|
||||
kind=@lib.SinkKind::File,
|
||||
path="bitlogger-config-demo.log",
|
||||
append=false,
|
||||
auto_flush=false,
|
||||
rotation=Some(@lib.file_rotation(128, max_backups=2)),
|
||||
text_formatter=formatter_config,
|
||||
)
|
||||
println(@lib.stringify_sink_config(sink_config))
|
||||
|
||||
let file_policy = @lib.FileSinkPolicy::new(
|
||||
append=false,
|
||||
auto_flush=false,
|
||||
rotation=Some(@lib.file_rotation(64, max_backups=2)),
|
||||
)
|
||||
println(@lib.stringify_file_sink_policy(file_policy))
|
||||
|
||||
let file_runtime_logger = @lib.build_logger(
|
||||
@lib.LoggerConfig::new(
|
||||
sink=@lib.SinkConfig::new(kind=@lib.SinkKind::File, path="bitlogger-runtime-demo.log"),
|
||||
queue=Some(@lib.QueueConfig::new(8)),
|
||||
),
|
||||
)
|
||||
file_runtime_logger.info("runtime file logger ready")
|
||||
match file_runtime_logger.file_runtime_state() {
|
||||
Some(snapshot) => println(@lib.stringify_runtime_file_state(snapshot, pretty=true))
|
||||
None => ()
|
||||
}
|
||||
ignore(file_runtime_logger.file_close())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user