mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
✨ Add explicit reopen-with-policy helper
This commit is contained in:
@@ -285,6 +285,8 @@ test "configured logger can reopen built file sink" {
|
||||
inspect(logger.file_append_mode(), content="false")
|
||||
inspect(logger.file_reopen(), content="true")
|
||||
inspect(logger.file_append_mode(), content="false")
|
||||
inspect(logger.file_reopen_with_current_policy(), content="true")
|
||||
inspect(logger.file_append_mode(), content="false")
|
||||
inspect(logger.close(), content="true")
|
||||
} else {
|
||||
inspect(logger.file_append_mode(), content="true")
|
||||
@@ -295,6 +297,8 @@ test "configured logger can reopen built file sink" {
|
||||
inspect(logger.file_open_failures(), content="2")
|
||||
inspect(logger.file_reopen(append=Some(false)), content="false")
|
||||
inspect(logger.file_append_mode(), content="false")
|
||||
inspect(logger.file_reopen_with_current_policy(), content="false")
|
||||
inspect(logger.file_open_failures(), content="3")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,6 +177,8 @@ test "file sink reopen and failure counters reflect backend state" {
|
||||
inspect(sink.append_mode(), content="false")
|
||||
inspect(sink.reopen(), content="true")
|
||||
inspect(sink.append_mode(), content="false")
|
||||
inspect(sink.reopen_with_current_policy(), content="true")
|
||||
inspect(sink.append_mode(), content="false")
|
||||
inspect(sink.close(), content="true")
|
||||
ignore(remove_file_internal("bitlogger-reopen.log"))
|
||||
} else {
|
||||
@@ -189,6 +191,8 @@ test "file sink reopen and failure counters reflect backend state" {
|
||||
inspect(sink.flush_failures(), content="0")
|
||||
inspect(sink.reopen(append=Some(false)), content="false")
|
||||
inspect(sink.append_mode(), content="false")
|
||||
inspect(sink.reopen_with_current_policy(), content="false")
|
||||
inspect(sink.open_failures(), content="3")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ BitLogger 是一个基于 MoonBit 的结构化日志库。
|
||||
- 支持 `parse_logger_config_text(...)`、`stringify_logger_config(...)` 进行最小 JSON 配置读写
|
||||
- config-driven logger assembly via `build_logger(...)`
|
||||
- 支持 `build_logger(...)` 将配置组装为可直接使用的 logger
|
||||
- native-only file output via `file_sink(...)`, with basic size rotation, backup retention, explicit `reopen()`, and failure counters
|
||||
- 支持 `file_sink(...)`、基础 size rotation / backup retention、显式 `reopen()` 与失败计数,但当前仅保证 `native/llvm` backend 可用
|
||||
- native-only file output via `file_sink(...)`, with basic size rotation, backup retention, explicit `reopen()` / `reopen_with_current_policy()`, and failure counters
|
||||
- 支持 `file_sink(...)`、基础 size rotation / backup retention、显式 `reopen()` / `reopen_with_current_policy()` 与失败计数,但当前仅保证 `native/llvm` backend 可用
|
||||
|
||||
## Example / 示例
|
||||
|
||||
@@ -220,7 +220,7 @@ test {
|
||||
- basic rotation is size-based / 当前基础轮转为按文件大小触发
|
||||
- `file_rotation(max_bytes, max_backups=...)` controls threshold and retained backups / `file_rotation(max_bytes, max_backups=...)` 控制触发阈值和保留备份数
|
||||
- JSON config uses `sink.rotation.max_bytes` and `sink.rotation.max_backups` / JSON 配置使用 `sink.rotation.max_bytes` 与 `sink.rotation.max_backups`
|
||||
- `FileSink::reopen()` can explicitly reopen the current file handle / `FileSink::reopen()` 可显式重开当前文件句柄
|
||||
- `FileSink::reopen()` can explicitly reopen the current file handle, and `FileSink::reopen_with_current_policy()` makes the stored-policy reopen path explicit / `FileSink::reopen()` 可显式重开当前文件句柄,`FileSink::reopen_with_current_policy()` 则把“按当前保存策略重开”变成显式动作
|
||||
- `append_mode()` exposes the current append policy, and `reopen(append=...)` updates that policy for later reopen calls / `append_mode()` 可读取当前 append 策略,`reopen(append=...)` 会更新后续 reopen 复用的 append 策略
|
||||
- `set_append_mode(...)` updates the stored append policy without forcing an immediate reopen / `set_append_mode(...)` 可直接更新保存的 append 策略,但不会强制立即 reopen
|
||||
- `path()` and `auto_flush_enabled()` expose core file sink policy state / `path()` 与 `auto_flush_enabled()` 可读取 file sink 的基础策略状态
|
||||
|
||||
@@ -231,6 +231,14 @@ pub fn RuntimeSink::file_reopen(self : RuntimeSink, append~ : Bool? = None) -> B
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_reopen_with_current_policy(self : RuntimeSink) -> Bool {
|
||||
match self {
|
||||
File(sink) => sink.reopen_with_current_policy()
|
||||
QueuedFile(sink) => sink.sink.reopen_with_current_policy()
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_append_mode(self : RuntimeSink) -> Bool {
|
||||
match self {
|
||||
File(sink) => sink.append_mode()
|
||||
@@ -411,6 +419,10 @@ pub fn ConfiguredLogger::file_reopen(self : ConfiguredLogger, append~ : Bool? =
|
||||
self.sink.file_reopen(append=append)
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_reopen_with_current_policy(self : ConfiguredLogger) -> Bool {
|
||||
self.sink.file_reopen_with_current_policy()
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_append_mode(self : ConfiguredLogger) -> Bool {
|
||||
self.sink.file_append_mode()
|
||||
}
|
||||
|
||||
@@ -197,6 +197,10 @@ pub fn FileSink::reopen(self : FileSink, append~ : Bool? = None) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn FileSink::reopen_with_current_policy(self : FileSink) -> Bool {
|
||||
self.reopen()
|
||||
}
|
||||
|
||||
fn rotated_file_path(path : String, index : Int) -> String {
|
||||
"\{path}.\{index}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user