mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-26 18:02:19 +00:00
✅ cover application alias composition
This commit is contained in:
@@ -1041,6 +1041,47 @@ async test "application async logger keeps async helper surface" {
|
||||
inspect(logger.last_error(), content="")
|
||||
}
|
||||
|
||||
async test "application async logger keeps broader async composition surface" {
|
||||
let logger : ApplicationAsyncLogger = build_application_async_logger(
|
||||
AsyncLoggerBuildConfig::new(
|
||||
logger=@bitlogger.LoggerConfig::new(
|
||||
min_level=@bitlogger.Level::Warn,
|
||||
target="async.app.compose",
|
||||
sink=@bitlogger.SinkConfig::new(kind=@bitlogger.SinkKind::Console),
|
||||
),
|
||||
async_config=AsyncLoggerConfig::new(
|
||||
max_pending=2,
|
||||
overflow=AsyncOverflowPolicy::DropNewest,
|
||||
flush=AsyncFlushPolicy::Shutdown,
|
||||
),
|
||||
),
|
||||
)
|
||||
.with_timestamp()
|
||||
.with_context_fields([@bitlogger.field("service", "bitlogger")])
|
||||
.child("worker")
|
||||
|
||||
inspect(logger.target, content="async.app.compose.worker")
|
||||
inspect(logger.timestamp, content="true")
|
||||
inspect(logger.is_enabled(@bitlogger.Level::Error), content="true")
|
||||
inspect(logger.is_enabled(@bitlogger.Level::Info), content="false")
|
||||
|
||||
logger.error("one")
|
||||
logger.error("two")
|
||||
inspect(logger.pending_count(), content="2")
|
||||
inspect(logger.dropped_count(), content="0")
|
||||
|
||||
@async.with_task_group(group => {
|
||||
group.spawn_bg(() => logger.run())
|
||||
logger.shutdown()
|
||||
})
|
||||
|
||||
inspect(logger.is_closed(), content="true")
|
||||
inspect(logger.pending_count(), content="0")
|
||||
inspect(logger.dropped_count(), content="0")
|
||||
inspect(logger.has_failed(), content="false")
|
||||
inspect(logger.last_error(), content="")
|
||||
}
|
||||
|
||||
test "application async logger builder preserves sync queue-backed runtime sink" {
|
||||
let logger = build_application_async_logger(
|
||||
AsyncLoggerBuildConfig::new(
|
||||
|
||||
@@ -1510,6 +1510,37 @@ test "application logger keeps configured runtime helper surface" {
|
||||
}
|
||||
}
|
||||
|
||||
test "application logger keeps broader logger composition surface" {
|
||||
let logger : ApplicationLogger = build_application_logger(
|
||||
LoggerConfig::new(
|
||||
min_level=Level::Warn,
|
||||
target="app.compose",
|
||||
queue=Some(QueueConfig::new(2, overflow=QueueOverflowPolicy::DropNewest)),
|
||||
sink=SinkConfig::new(kind=SinkKind::Console),
|
||||
),
|
||||
)
|
||||
let derived = logger.with_timestamp().child("worker")
|
||||
|
||||
inspect(derived.target, content="app.compose.worker")
|
||||
inspect(derived.timestamp, content="true")
|
||||
inspect(derived.is_enabled(Level::Error), content="true")
|
||||
inspect(derived.is_enabled(Level::Info), content="false")
|
||||
inspect(match derived.sink {
|
||||
RuntimeSink::QueuedConsole(_) => "QueuedConsole"
|
||||
RuntimeSink::QueuedJsonConsole(_) => "QueuedJsonConsole"
|
||||
RuntimeSink::QueuedTextConsole(_) => "QueuedTextConsole"
|
||||
RuntimeSink::QueuedFile(_) => "QueuedFile"
|
||||
_ => "Other"
|
||||
}, content="QueuedConsole")
|
||||
|
||||
derived.error("one")
|
||||
derived.error("two")
|
||||
inspect(derived.pending_count(), content="2")
|
||||
inspect(derived.dropped_count(), content="0")
|
||||
inspect(derived.flush(), content="2")
|
||||
inspect(derived.pending_count(), content="0")
|
||||
}
|
||||
|
||||
test "application logger can be built from config text" {
|
||||
let logger = parse_and_build_application_logger(
|
||||
"{\"min_level\":\"warn\",\"target\":\"app.json\",\"sink\":{\"kind\":\"console\"}}",
|
||||
|
||||
Reference in New Issue
Block a user