🔊 Update 1.0.0

This commit is contained in:
Nanaloveyuki
2026-06-27 10:45:36 +08:00
parent 7557e37cc8
commit c8023b0ded
55 changed files with 5734 additions and 2360 deletions
+97 -45
View File
@@ -1,39 +1,56 @@
///|
test "logger config presets use expected defaults" {
let console_config = console()
inspect(console_config.min_level.label(), content="INFO")
inspect(console_config.target, content="")
inspect(console_config.timestamp, content="false")
inspect(match console_config.sink.kind {
SinkKind::Console => "Console"
_ => "other"
}, content="Console")
inspect(
match console_config.sink.kind {
SinkKind::Console => "Console"
_ => "other"
},
content="Console",
)
inspect(console_config.queue is None, content="true")
let json_config = json_console()
inspect(match json_config.sink.kind {
SinkKind::JsonConsole => "JsonConsole"
_ => "other"
}, content="JsonConsole")
inspect(
match json_config.sink.kind {
SinkKind::JsonConsole => "JsonConsole"
_ => "other"
},
content="JsonConsole",
)
inspect(json_config.queue is None, content="true")
let text_config = text_console()
inspect(match text_config.sink.kind {
SinkKind::TextConsole => "TextConsole"
_ => "other"
}, content="TextConsole")
inspect(
match text_config.sink.kind {
SinkKind::TextConsole => "TextConsole"
_ => "other"
},
content="TextConsole",
)
inspect(text_config.sink.text_formatter.show_timestamp, content="true")
inspect(color_mode_label(text_config.sink.text_formatter.color_mode), content="never")
inspect(
color_mode_label(text_config.sink.text_formatter.color_mode),
content="never",
)
}
///|
test "file preset uses file sink defaults" {
let config = file("bitlogger.log")
inspect(config.min_level.label(), content="INFO")
inspect(config.target, content="")
inspect(config.timestamp, content="false")
inspect(match config.sink.kind {
SinkKind::File => "File"
_ => "other"
}, content="File")
inspect(
match config.sink.kind {
SinkKind::File => "File"
_ => "other"
},
content="File",
)
inspect(config.sink.path, content="bitlogger.log")
inspect(config.sink.append, content="true")
inspect(config.sink.auto_flush, content="true")
@@ -41,6 +58,7 @@ test "file preset uses file sink defaults" {
inspect(config.queue is None, content="true")
}
///|
test "file preset rejects empty path like parser file sink config" {
let preset_error = (fn() -> String raise ConfigError {
ignore(file(""))
@@ -51,7 +69,9 @@ test "file preset rejects empty path like parser file sink config" {
inspect(preset_error, content="File sink requires non-empty path")
let parser_error = (fn() -> String raise ConfigError {
ignore(parse_logger_config_text("{\"sink\":{\"kind\":\"file\",\"path\":\"\"}}"))
ignore(
parse_logger_config_text("{\"sink\":{\"kind\":\"file\",\"path\":\"\"}}"),
)
"no error"
})() catch {
ConfigError::InvalidConfig(message) => message
@@ -59,8 +79,12 @@ test "file preset rejects empty path like parser file sink config" {
inspect(parser_error, content="File sink requires non-empty path")
}
///|
test "preset helpers compose queue and file rotation without losing config" {
let formatter = TextFormatterConfig::new(show_timestamp=false, separator=" | ")
let formatter = TextFormatterConfig::new(
show_timestamp=false,
separator=" | ",
)
let config = file(
"service.log",
min_level=Level::Warn,
@@ -86,10 +110,13 @@ test "preset helpers compose queue and file rotation without losing config" {
match config.queue {
Some(queue) => {
inspect(queue.max_pending, content="32")
inspect(match queue.overflow {
QueueOverflowPolicy::DropNewest => "DropNewest"
QueueOverflowPolicy::DropOldest => "DropOldest"
}, content="DropOldest")
inspect(
match queue.overflow {
QueueOverflowPolicy::DropNewest => "DropNewest"
QueueOverflowPolicy::DropOldest => "DropOldest"
},
content="DropOldest",
)
}
None => inspect(false, content="true")
}
@@ -102,6 +129,7 @@ test "preset helpers compose queue and file rotation without losing config" {
}
}
///|
test "queue helper preserves file rotation when applied after rotation" {
let config = with_queue(
with_file_rotation(file("service.log", append=false), 256, max_backups=2),
@@ -113,10 +141,13 @@ test "queue helper preserves file rotation when applied after rotation" {
match config.queue {
Some(queue) => {
inspect(queue.max_pending, content="8")
inspect(match queue.overflow {
QueueOverflowPolicy::DropNewest => "DropNewest"
QueueOverflowPolicy::DropOldest => "DropOldest"
}, content="DropNewest")
inspect(
match queue.overflow {
QueueOverflowPolicy::DropNewest => "DropNewest"
QueueOverflowPolicy::DropOldest => "DropOldest"
},
content="DropNewest",
)
}
None => inspect(false, content="true")
}
@@ -129,29 +160,44 @@ test "queue helper preserves file rotation when applied after rotation" {
}
}
///|
test "file rotation helper leaves non-file presets unchanged" {
let console_config = with_file_rotation(console(target="console"), 64, max_backups=2)
inspect(match console_config.sink.kind {
SinkKind::Console => "Console"
_ => "other"
}, content="Console")
let console_config = with_file_rotation(
console(target="console"),
64,
max_backups=2,
)
inspect(
match console_config.sink.kind {
SinkKind::Console => "Console"
_ => "other"
},
content="Console",
)
inspect(console_config.target, content="console")
inspect(console_config.sink.rotation is None, content="true")
let text_config = with_file_rotation(
text_console(target="text", text_formatter=TextFormatterConfig::new(separator=" :: ")),
text_console(
target="text",
text_formatter=TextFormatterConfig::new(separator=" :: "),
),
96,
max_backups=4,
)
inspect(match text_config.sink.kind {
SinkKind::TextConsole => "TextConsole"
_ => "other"
}, content="TextConsole")
inspect(
match text_config.sink.kind {
SinkKind::TextConsole => "TextConsole"
_ => "other"
},
content="TextConsole",
)
inspect(text_config.target, content="text")
inspect(text_config.sink.text_formatter.separator, content=" :: ")
inspect(text_config.sink.rotation is None, content="true")
}
///|
test "file rotation helper keeps queued non-file presets unchanged" {
let config = with_queue(
json_console(min_level=Level::Error, target="json"),
@@ -161,18 +207,24 @@ test "file rotation helper keeps queued non-file presets unchanged" {
let rotated = with_file_rotation(config, 512, max_backups=5)
inspect(rotated.min_level.label(), content="ERROR")
inspect(rotated.target, content="json")
inspect(match rotated.sink.kind {
SinkKind::JsonConsole => "JsonConsole"
_ => "other"
}, content="JsonConsole")
inspect(
match rotated.sink.kind {
SinkKind::JsonConsole => "JsonConsole"
_ => "other"
},
content="JsonConsole",
)
inspect(rotated.sink.rotation is None, content="true")
match rotated.queue {
Some(queue) => {
inspect(queue.max_pending, content="4")
inspect(match queue.overflow {
QueueOverflowPolicy::DropNewest => "DropNewest"
QueueOverflowPolicy::DropOldest => "DropOldest"
}, content="DropOldest")
inspect(
match queue.overflow {
QueueOverflowPolicy::DropNewest => "DropNewest"
QueueOverflowPolicy::DropOldest => "DropOldest"
},
content="DropOldest",
)
}
None => inspect(false, content="true")
}