mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
✅ Add coverage for release helper APIs
This commit is contained in:
@@ -280,6 +280,23 @@ async test "library async logger can be built from config" {
|
||||
inspect(full.target, content="async.lib.config")
|
||||
}
|
||||
|
||||
test "library async text logger can be built from typed config" {
|
||||
let logger = build_library_async_text_logger(
|
||||
AsyncLoggerBuildConfig::new(
|
||||
logger=@bitlogger.text_console(
|
||||
min_level=@bitlogger.Level::Warn,
|
||||
target="async.lib.text",
|
||||
text_formatter=@bitlogger.TextFormatterConfig::new(show_timestamp=false, separator=" | "),
|
||||
),
|
||||
async_config=AsyncLoggerConfig::new(max_pending=2),
|
||||
),
|
||||
)
|
||||
let full = logger.to_async_logger()
|
||||
inspect(logger.is_enabled(@bitlogger.Level::Error), content="true")
|
||||
inspect(logger.is_enabled(@bitlogger.Level::Info), content="false")
|
||||
inspect(full.target, content="async.lib.text")
|
||||
}
|
||||
|
||||
async test "async logger can project to library async logger" {
|
||||
let logger = build_async_logger(
|
||||
AsyncLoggerBuildConfig::new(
|
||||
@@ -304,6 +321,48 @@ test "application async logger aliases runtime async entry" {
|
||||
inspect(logger.target, content="async.app")
|
||||
}
|
||||
|
||||
test "application text async logger uses text facade build path" {
|
||||
let logger = build_application_text_async_logger(
|
||||
AsyncLoggerBuildConfig::new(
|
||||
logger=@bitlogger.text_console(
|
||||
min_level=@bitlogger.Level::Warn,
|
||||
target="async.app.text",
|
||||
text_formatter=@bitlogger.TextFormatterConfig::new(show_timestamp=false, separator=" | "),
|
||||
),
|
||||
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.text")
|
||||
}
|
||||
|
||||
test "build async text logger keeps text-console config fields" {
|
||||
let logger = build_async_text_logger(
|
||||
AsyncLoggerBuildConfig::new(
|
||||
logger=@bitlogger.LoggerConfig::new(
|
||||
min_level=@bitlogger.Level::Warn,
|
||||
target="async.text.direct",
|
||||
timestamp=true,
|
||||
sink=@bitlogger.SinkConfig::new(
|
||||
kind=@bitlogger.SinkKind::TextConsole,
|
||||
text_formatter=@bitlogger.TextFormatterConfig::new(show_timestamp=false, separator=" | "),
|
||||
),
|
||||
),
|
||||
async_config=AsyncLoggerConfig::new(max_pending=3, overflow=AsyncOverflowPolicy::DropOldest),
|
||||
),
|
||||
)
|
||||
inspect(logger.is_enabled(@bitlogger.Level::Error), content="true")
|
||||
inspect(logger.is_enabled(@bitlogger.Level::Info), content="false")
|
||||
inspect(logger.target, content="async.text.direct")
|
||||
inspect(logger.timestamp, content="true")
|
||||
inspect(match logger.flush_policy() {
|
||||
AsyncFlushPolicy::Never => "Never"
|
||||
AsyncFlushPolicy::Batch => "Batch"
|
||||
AsyncFlushPolicy::Shutdown => "Shutdown"
|
||||
}, content="Never")
|
||||
}
|
||||
|
||||
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\"}}",
|
||||
|
||||
@@ -242,6 +242,32 @@ test "config subtype json helpers stringify stable shapes" {
|
||||
)
|
||||
}
|
||||
|
||||
test "default config helpers expose baseline config shapes" {
|
||||
let formatter = default_text_formatter_config()
|
||||
inspect(formatter.show_timestamp, content="true")
|
||||
inspect(color_mode_label(formatter.color_mode), content="never")
|
||||
inspect(color_support_label(formatter.color_support), content="truecolor")
|
||||
inspect(style_markup_mode_label(formatter.style_markup), content="full")
|
||||
|
||||
let sink = default_sink_config()
|
||||
inspect(match sink.kind {
|
||||
SinkKind::Console => "Console"
|
||||
_ => "other"
|
||||
}, content="Console")
|
||||
inspect(sink.path, content="")
|
||||
inspect(sink.rotation is None, content="true")
|
||||
|
||||
let logger = default_logger_config()
|
||||
inspect(logger.min_level.label(), content="INFO")
|
||||
inspect(logger.target, content="")
|
||||
inspect(logger.timestamp, content="false")
|
||||
inspect(logger.queue is None, content="true")
|
||||
inspect(match logger.sink.kind {
|
||||
SinkKind::Console => "Console"
|
||||
_ => "other"
|
||||
}, content="Console")
|
||||
}
|
||||
|
||||
test "config basic color support downgrades hex colors" {
|
||||
let formatter = TextFormatterConfig::new(
|
||||
show_level=false,
|
||||
@@ -835,6 +861,15 @@ test "configured logger can project to library logger" {
|
||||
inspect(logger.to_logger().target, content="lib.projected")
|
||||
}
|
||||
|
||||
test "default library logger mirrors shared sync defaults" {
|
||||
set_default_min_level(Level::Warn)
|
||||
set_default_target("lib.default")
|
||||
let logger = default_library_logger()
|
||||
inspect(logger.is_enabled(Level::Error), content="true")
|
||||
inspect(logger.is_enabled(Level::Info), content="false")
|
||||
inspect(logger.to_logger().target, content="lib.default")
|
||||
}
|
||||
|
||||
test "application logger aliases configured runtime entry" {
|
||||
let logger = build_application_logger(
|
||||
LoggerConfig::new(min_level=Level::Warn, target="app.runtime"),
|
||||
|
||||
@@ -255,6 +255,19 @@ test "global style tags apply when formatter has no local registry" {
|
||||
set_global_style_tag_registry(previous)
|
||||
}
|
||||
|
||||
test "reset global style tag registry restores builtin defaults" {
|
||||
set_global_style_tag_registry(style_tag_registry().set_tag("accent", fg=Some("#123456"), bold=true))
|
||||
reset_global_style_tag_registry()
|
||||
let rec = record(Level::Info, "<success>ok</>")
|
||||
inspect(
|
||||
format_text(
|
||||
rec,
|
||||
formatter=text_formatter(show_level=false, show_target=false, color_mode=ColorMode::Always),
|
||||
),
|
||||
content="\u{001b}[32;1mok\u{001b}[0m",
|
||||
)
|
||||
}
|
||||
|
||||
test "style tag alias can reuse builtin tags" {
|
||||
let formatter = text_formatter(
|
||||
show_level=false,
|
||||
|
||||
Reference in New Issue
Block a user