Clarify application and library logger entries

This commit is contained in:
Nanaloveyuki
2026-05-15 11:42:46 +08:00
parent 1b56e1e20a
commit 78423384ea
6 changed files with 105 additions and 4 deletions
+33
View File
@@ -279,3 +279,36 @@ async test "library async logger can be built from config" {
inspect(logger.is_enabled(@bitlogger.Level::Info), content="false")
inspect(full.target, content="async.lib.config")
}
async test "async logger can project to library async logger" {
let logger = build_async_logger(
AsyncLoggerBuildConfig::new(
logger=@bitlogger.LoggerConfig::new(target="async.projected", min_level=@bitlogger.Level::Warn),
async_config=AsyncLoggerConfig::new(max_pending=2),
),
).to_library_async_logger()
inspect(logger.is_enabled(@bitlogger.Level::Error), content="true")
inspect(logger.is_enabled(@bitlogger.Level::Info), content="false")
inspect(logger.to_async_logger().target, content="async.projected")
}
test "application async logger aliases runtime async entry" {
let logger = build_application_async_logger(
AsyncLoggerBuildConfig::new(
logger=@bitlogger.LoggerConfig::new(target="async.app", min_level=@bitlogger.Level::Warn),
async_config=AsyncLoggerConfig::new(max_pending=2),
),
)
inspect(logger.is_enabled(@bitlogger.Level::Error), content="true")
inspect(logger.is_enabled(@bitlogger.Level::Info), content="false")
inspect(logger.target, content="async.app")
}
test "application async logger can be built from config text" {
let logger = parse_and_build_application_async_logger(
"{\"logger\":{\"min_level\":\"warn\",\"target\":\"async.app.json\",\"sink\":{\"kind\":\"console\"}},\"async_config\":{\"max_pending\":2,\"overflow\":\"DropNewest\",\"max_batch\":1,\"linger_ms\":0,\"flush\":\"Never\"}}",
)
inspect(logger.is_enabled(@bitlogger.Level::Error), content="true")
inspect(logger.is_enabled(@bitlogger.Level::Info), content="false")
inspect(logger.target, content="async.app.json")
}
+21
View File
@@ -0,0 +1,21 @@
pub type ApplicationAsyncLogger = AsyncLogger[@bitlogger.RuntimeSink]
pub type ApplicationTextAsyncLogger = AsyncLogger[@bitlogger.FormattedConsoleSink]
pub fn build_application_async_logger(
config : AsyncLoggerBuildConfig,
) -> ApplicationAsyncLogger {
build_async_logger(config)
}
pub fn build_application_text_async_logger(
config : AsyncLoggerBuildConfig,
) -> ApplicationTextAsyncLogger {
build_async_text_logger(config)
}
pub fn parse_and_build_application_async_logger(
input : String,
) -> ApplicationAsyncLogger raise {
build_application_async_logger(parse_async_logger_build_config_text(input))
}
+6 -2
View File
@@ -2,10 +2,14 @@ pub struct LibraryAsyncLogger[S] {
inner : AsyncLogger[S]
}
pub fn[S] library_async_logger(logger : AsyncLogger[S]) -> LibraryAsyncLogger[S] {
fn[S] library_async_logger(logger : AsyncLogger[S]) -> LibraryAsyncLogger[S] {
{ inner: logger }
}
pub fn[S] AsyncLogger::to_library_async_logger(self : AsyncLogger[S]) -> LibraryAsyncLogger[S] {
library_async_logger(self)
}
pub fn[S] LibraryAsyncLogger::new(
sink : S,
config~ : AsyncLoggerConfig = AsyncLoggerConfig::new(),
@@ -28,7 +32,7 @@ pub fn[S] LibraryAsyncLogger::to_async_logger(self : LibraryAsyncLogger[S]) -> A
self.inner
}
pub fn[S] configured_library_async_logger(
fn[S] configured_library_async_logger(
logger : AsyncLogger[S],
) -> LibraryAsyncLogger[S] {
library_async_logger(logger)