mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
✨ Add file sink state snapshots
This commit is contained in:
@@ -206,8 +206,13 @@ test "configured logger exposes file sink observability helpers" {
|
||||
),
|
||||
),
|
||||
)
|
||||
let state = logger.file_state()
|
||||
inspect(logger.file_available() == native_files_supported(), content="true")
|
||||
inspect(logger.file_path(), content="config-file.log")
|
||||
inspect(state.path, content="config-file.log")
|
||||
inspect(state.available == logger.file_available(), content="true")
|
||||
inspect(state.append == logger.file_append_mode(), content="true")
|
||||
inspect(state.auto_flush == logger.file_auto_flush(), content="true")
|
||||
inspect(logger.file_append_mode(), content="true")
|
||||
inspect(logger.file_auto_flush(), content="false")
|
||||
inspect(logger.file_rotation_enabled(), content="true")
|
||||
@@ -264,6 +269,10 @@ test "configured logger file setters update file sink policy state" {
|
||||
inspect(logger.file_rotation_config() is None, content="true")
|
||||
inspect(logger.file_reopen(), content=if logger.file_available() { "true" } else { "false" })
|
||||
inspect(logger.file_append_mode(), content="false")
|
||||
let state = logger.file_state()
|
||||
inspect(state.append, content="false")
|
||||
inspect(state.auto_flush, content="false")
|
||||
inspect(state.rotation is None, content="true")
|
||||
ignore(logger.close())
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,14 @@ test "native file support flag is queryable" {
|
||||
|
||||
test "file sink availability reflects backend support" {
|
||||
let sink = file_sink("bitlogger-test.log")
|
||||
let state = sink.state()
|
||||
inspect(sink.path(), content="bitlogger-test.log")
|
||||
inspect(sink.is_available() == native_files_supported(), content="true")
|
||||
inspect(state.path, content="bitlogger-test.log")
|
||||
inspect(state.available == sink.is_available(), content="true")
|
||||
inspect(state.append == sink.append_mode(), content="true")
|
||||
inspect(state.auto_flush == sink.auto_flush_enabled(), content="true")
|
||||
inspect((state.rotation is None) == (sink.rotation_config() is None), content="true")
|
||||
inspect(sink.append_mode(), content="true")
|
||||
inspect(sink.auto_flush_enabled(), content="true")
|
||||
inspect(sink.rotation_enabled(), content="false")
|
||||
@@ -145,6 +151,10 @@ test "file sink setters update auto flush and rotation state" {
|
||||
inspect(sink.rotation_config() is None, content="true")
|
||||
inspect(sink.reopen(), content=if sink.is_available() { "true" } else { "false" })
|
||||
inspect(sink.append_mode(), content="false")
|
||||
let state = sink.state()
|
||||
inspect(state.append, content="false")
|
||||
inspect(state.auto_flush, content="false")
|
||||
inspect(state.rotation is None, content="true")
|
||||
}
|
||||
|
||||
test "file sink tracks rotation failures on unavailable backend" {
|
||||
|
||||
@@ -225,7 +225,8 @@ test {
|
||||
- `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 的基础策略状态
|
||||
- `rotation_enabled()` and `rotation_config()` expose whether rotation is active and which settings are currently applied / `rotation_enabled()` 与 `rotation_config()` 可读取 rotation 是否启用及当前配置参数
|
||||
- `state()` exposes a single file-sink snapshot including path, availability, append policy, auto-flush, rotation config, and failure counters / `state()` 可一次性读取包含 path、availability、append、auto-flush、rotation 配置与失败计数的 file sink 快照
|
||||
- `set_auto_flush(...)`, `set_rotation(...)`, and `clear_rotation()` allow runtime tuning of core file sink policies / `set_auto_flush(...)`、`set_rotation(...)`、`clear_rotation()` 可在运行期调整 file sink 的基础策略
|
||||
- `open_failures()`、`write_failures()`、`flush_failures()`、`rotation_failures()` expose basic sink health counters / `open_failures()`、`write_failures()`、`flush_failures()`、`rotation_failures()` 可用于观察基础 sink 健康状态
|
||||
- `ConfiguredLogger` also forwards file reopen, flush, close, append-mode, path, auto-flush, rotation-config, append setter, policy setter, and failure-counter helpers for config-built file sinks / `ConfiguredLogger` 也会为配置生成的 file sink 转发 reopen、flush、close、append-mode、path、auto-flush、rotation 配置、append setter、策略 setter 与失败计数访问器
|
||||
- `ConfiguredLogger` also forwards file reopen, flush, close, append-mode, path, auto-flush, rotation-config, state snapshot, append setter, policy setter, and failure-counter helpers for config-built file sinks / `ConfiguredLogger` 也会为配置生成的 file sink 转发 reopen、flush、close、append-mode、path、auto-flush、rotation 配置、state 快照、append setter、策略 setter 与失败计数访问器
|
||||
- current scope is observability-first, not a full self-healing sink runtime / 当前定位仍以可观测性优先,不是完整自愈型 sink runtime
|
||||
|
||||
@@ -405,6 +405,24 @@ pub fn RuntimeSink::file_rotation_failures(self : RuntimeSink) -> Int {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_state(self : RuntimeSink) -> FileSinkState {
|
||||
match self {
|
||||
File(sink) => sink.state()
|
||||
QueuedFile(sink) => sink.sink.state()
|
||||
_ => {
|
||||
path: "",
|
||||
available: false,
|
||||
append: false,
|
||||
auto_flush: false,
|
||||
rotation: None,
|
||||
open_failures: 0,
|
||||
write_failures: 0,
|
||||
flush_failures: 0,
|
||||
rotation_failures: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type ConfiguredLogger = Logger[RuntimeSink]
|
||||
|
||||
pub fn ConfiguredLogger::flush(self : ConfiguredLogger) -> Int {
|
||||
@@ -510,6 +528,10 @@ pub fn ConfiguredLogger::file_rotation_failures(self : ConfiguredLogger) -> Int
|
||||
self.sink.file_rotation_failures()
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_state(self : ConfiguredLogger) -> FileSinkState {
|
||||
self.sink.file_state()
|
||||
}
|
||||
|
||||
fn expect_object(
|
||||
value : @json_parser.JsonValue,
|
||||
context : String,
|
||||
|
||||
@@ -62,6 +62,18 @@ pub struct FileRotation {
|
||||
max_backups : Int
|
||||
}
|
||||
|
||||
pub struct FileSinkState {
|
||||
path : String
|
||||
available : Bool
|
||||
append : Bool
|
||||
auto_flush : Bool
|
||||
rotation : FileRotation?
|
||||
open_failures : Int
|
||||
write_failures : Int
|
||||
flush_failures : Int
|
||||
rotation_failures : Int
|
||||
}
|
||||
|
||||
pub fn file_rotation(max_bytes : Int, max_backups~ : Int = 1) -> FileRotation {
|
||||
{
|
||||
max_bytes: if max_bytes <= 0 { 1 } else { max_bytes },
|
||||
@@ -177,6 +189,20 @@ pub fn FileSink::flush_failures(self : FileSink) -> Int {
|
||||
self.flush_failures.val
|
||||
}
|
||||
|
||||
pub fn FileSink::state(self : FileSink) -> FileSinkState {
|
||||
{
|
||||
path: self.path,
|
||||
available: self.is_available(),
|
||||
append: self.append.val,
|
||||
auto_flush: self.auto_flush.val,
|
||||
rotation: self.rotation.val,
|
||||
open_failures: self.open_failures.val,
|
||||
write_failures: self.write_failures.val,
|
||||
flush_failures: self.flush_failures.val,
|
||||
rotation_failures: self.rotation_failures.val,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn FileSink::reopen(self : FileSink, append~ : Bool? = None) -> Bool {
|
||||
let append_mode = append.unwrap_or(self.append.val)
|
||||
self.append.val = append_mode
|
||||
|
||||
Reference in New Issue
Block a user