cover application alias helper surface

This commit is contained in:
Nanaloveyuki
2026-06-14 03:21:09 +08:00
parent 17dbdfffde
commit 11db21a500
2 changed files with 79 additions and 0 deletions
+50
View File
@@ -991,6 +991,56 @@ test "application async logger aliases runtime async entry" {
inspect(logger.target, content="async.app")
}
async test "application async logger keeps async helper surface" {
let logger : ApplicationAsyncLogger = build_application_async_logger(
AsyncLoggerBuildConfig::new(
logger=@bitlogger.LoggerConfig::new(
min_level=@bitlogger.Level::Warn,
target="async.app.alias",
sink=@bitlogger.SinkConfig::new(kind=@bitlogger.SinkKind::Console),
),
async_config=AsyncLoggerConfig::new(
max_pending=2,
overflow=AsyncOverflowPolicy::DropOldest,
flush=AsyncFlushPolicy::Shutdown,
),
),
)
let state = logger.state()
inspect(state.pending_count, content="0")
inspect(state.dropped_count, content="0")
inspect(state.is_closed, content="false")
inspect(state.is_running, content="false")
inspect(state.has_failed, content="false")
inspect(match state.flush_policy {
AsyncFlushPolicy::Never => "Never"
AsyncFlushPolicy::Batch => "Batch"
AsyncFlushPolicy::Shutdown => "Shutdown"
}, content="Shutdown")
logger.info("skip")
logger.error("one")
logger.error("two")
logger.error("three")
inspect(logger.pending_count(), content="2")
inspect(logger.dropped_count(), content="1")
inspect(logger.is_closed(), content="false")
inspect(logger.is_running(), content="false")
@async.with_task_group(group => {
group.spawn_bg(() => logger.run())
logger.shutdown()
})
inspect(logger.is_closed(), content="true")
inspect(logger.is_running(), content="false")
inspect(logger.pending_count(), content="0")
inspect(logger.dropped_count(), content="1")
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(
+29
View File
@@ -1481,6 +1481,35 @@ test "application logger aliases configured runtime entry" {
inspect(logger.target, content="app.runtime")
}
test "application logger keeps configured runtime helper surface" {
let logger : ApplicationLogger = build_application_logger(
LoggerConfig::new(
min_level=Level::Warn,
target="app.alias.helpers",
sink=SinkConfig::new(kind=SinkKind::File, path="app-alias.log"),
queue=Some(QueueConfig::new(2, overflow=QueueOverflowPolicy::DropOldest)),
),
)
logger.error("one")
logger.error("two")
logger.error("three")
inspect(logger.pending_count(), content="2")
inspect(logger.dropped_count(), content="1")
inspect(logger.file_policy().append, content="true")
inspect(logger.file_runtime_state() is None, content="false")
inspect(logger.flush(), content="2")
inspect(logger.pending_count(), content="0")
if logger.file_available() {
inspect(logger.file_flush(), content="true")
inspect(logger.file_close(), content="true")
} else {
inspect(logger.file_flush(), content="false")
inspect(logger.file_close(), content="false")
}
}
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\"}}",