Add file failure counter reset helpers

This commit is contained in:
Nanaloveyuki
2026-05-10 13:18:29 +08:00
parent d8c9bf849f
commit c637631a30
8 changed files with 57 additions and 0 deletions
+2
View File
@@ -246,9 +246,11 @@ match logger.file_runtime_state() {
- `file_sink(...)` 也可直接读取 `path()``auto_flush_enabled()` 等基础 file 策略状态 - `file_sink(...)` 也可直接读取 `path()``auto_flush_enabled()` 等基础 file 策略状态
- `file_sink(...)` 还提供 `rotation_enabled()``rotation_config()`,可直接查询当前 rotation 策略是否启用及其参数 - `file_sink(...)` 还提供 `rotation_enabled()``rotation_config()`,可直接查询当前 rotation 策略是否启用及其参数
- `file_sink(...)` 还提供 `state()`,可一次性读取 path、available、append、auto_flush、rotation 与各类 failure counter 快照 - `file_sink(...)` 还提供 `state()`,可一次性读取 path、available、append、auto_flush、rotation 与各类 failure counter 快照
- `file_sink(...)` 还提供 `reset_failure_counters()`,可在完成排障后清空 open/write/flush/rotation 失败计数
- `file_sink(...)` 也支持 `set_auto_flush(...)``set_rotation(...)``clear_rotation()`,可在运行期调整基础写出策略 - `file_sink(...)` 也支持 `set_auto_flush(...)``set_rotation(...)``clear_rotation()`,可在运行期调整基础写出策略
- `build_logger(...)` 产出的 `ConfiguredLogger` 同样提供 `file_reopen()``file_reopen_with_current_policy()``file_reopen_append()``file_reopen_truncate()``file_flush()``file_close()``file_append_mode()``file_path()``file_auto_flush()``file_rotation_enabled()``file_rotation_config()``file_state()`,以及 `file_set_append_mode(...)``file_set_auto_flush(...)``file_set_rotation(...)``file_clear_rotation()` 与对应 file failure 计数访问器,便于配置式接入后继续运维控制 - `build_logger(...)` 产出的 `ConfiguredLogger` 同样提供 `file_reopen()``file_reopen_with_current_policy()``file_reopen_append()``file_reopen_truncate()``file_flush()``file_close()``file_append_mode()``file_path()``file_auto_flush()``file_rotation_enabled()``file_rotation_config()``file_state()`,以及 `file_set_append_mode(...)``file_set_auto_flush(...)``file_set_rotation(...)``file_clear_rotation()` 与对应 file failure 计数访问器,便于配置式接入后继续运维控制
- `ConfiguredLogger` 还提供 `file_runtime_state()`,可在 file sink 外层包了 queue 时同时读取底层 file 快照、是否 queue 包装、当前 pending 与 dropped 计数 - `ConfiguredLogger` 还提供 `file_runtime_state()`,可在 file sink 外层包了 queue 时同时读取底层 file 快照、是否 queue 包装、当前 pending 与 dropped 计数
- `ConfiguredLogger` 也支持 `file_reset_failure_counters()`,可在配置式 file sink 上统一清空失败计数
- `file_sink_state_to_json(...)``stringify_file_sink_state(...)``runtime_file_state_to_json(...)``stringify_runtime_file_state(...)` 可直接把 file / queued-file 快照导出为 JSON,便于排障或上报 - `file_sink_state_to_json(...)``stringify_file_sink_state(...)``runtime_file_state_to_json(...)``stringify_runtime_file_state(...)` 可直接把 file / queued-file 快照导出为 JSON,便于排障或上报
- `sink.text_formatter.template` 当前支持固定 token`{timestamp}``{timestamp_ms}``{level}``{target}``{message}``{fields}` - `sink.text_formatter.template` 当前支持固定 token`{timestamp}``{timestamp_ms}``{level}``{target}``{message}``{fields}`
- 当前可由配置直接组装的 sink 类型:`console``json_console``text_console``file` - 当前可由配置直接组装的 sink 类型:`console``json_console``text_console``file`
+15
View File
@@ -380,6 +380,11 @@ test "configured logger can reopen built file sink" {
inspect(logger.file_append_mode(), content="false") inspect(logger.file_append_mode(), content="false")
inspect(logger.file_reopen_append(), content="true") inspect(logger.file_reopen_append(), content="true")
inspect(logger.file_append_mode(), content="true") inspect(logger.file_append_mode(), content="true")
inspect(logger.file_reset_failure_counters(), content="true")
inspect(logger.file_open_failures(), content="0")
inspect(logger.file_write_failures(), content="0")
inspect(logger.file_flush_failures(), content="0")
inspect(logger.file_rotation_failures(), content="0")
inspect(logger.close(), content="true") inspect(logger.close(), content="true")
} else { } else {
inspect(logger.file_append_mode(), content="true") inspect(logger.file_append_mode(), content="true")
@@ -395,9 +400,19 @@ test "configured logger can reopen built file sink" {
inspect(logger.file_reopen_append(), content="false") inspect(logger.file_reopen_append(), content="false")
inspect(logger.file_append_mode(), content="true") inspect(logger.file_append_mode(), content="true")
inspect(logger.file_open_failures(), content="4") inspect(logger.file_open_failures(), content="4")
inspect(logger.file_reset_failure_counters(), content="true")
inspect(logger.file_open_failures(), content="0")
inspect(logger.file_write_failures(), content="0")
inspect(logger.file_flush_failures(), content="0")
inspect(logger.file_rotation_failures(), content="0")
} }
} }
test "configured non-file logger cannot reset file failure counters" {
let logger = build_logger(LoggerConfig::new(sink=SinkConfig::new(kind=SinkKind::Console)))
inspect(logger.file_reset_failure_counters(), content="false")
}
test "configured logger exposes file flush and close helpers" { test "configured logger exposes file flush and close helpers" {
let logger = build_logger( let logger = build_logger(
LoggerConfig::new( LoggerConfig::new(
+10
View File
@@ -191,6 +191,11 @@ test "file sink reopen and failure counters reflect backend state" {
inspect(sink.append_mode(), content="false") inspect(sink.append_mode(), content="false")
inspect(sink.reopen_append(), content="true") inspect(sink.reopen_append(), content="true")
inspect(sink.append_mode(), content="true") inspect(sink.append_mode(), content="true")
sink.reset_failure_counters()
inspect(sink.open_failures(), content="0")
inspect(sink.write_failures(), content="0")
inspect(sink.flush_failures(), content="0")
inspect(sink.rotation_failures(), content="0")
inspect(sink.close(), content="true") inspect(sink.close(), content="true")
ignore(remove_file_internal("bitlogger-reopen.log")) ignore(remove_file_internal("bitlogger-reopen.log"))
} else { } else {
@@ -208,6 +213,11 @@ test "file sink reopen and failure counters reflect backend state" {
inspect(sink.reopen_append(), content="false") inspect(sink.reopen_append(), content="false")
inspect(sink.append_mode(), content="true") inspect(sink.append_mode(), content="true")
inspect(sink.open_failures(), content="4") inspect(sink.open_failures(), content="4")
sink.reset_failure_counters()
inspect(sink.open_failures(), content="0")
inspect(sink.write_failures(), content="0")
inspect(sink.flush_failures(), content="0")
inspect(sink.rotation_failures(), content="0")
} }
} }
+2
View File
@@ -242,9 +242,11 @@ test {
- `path()` and `auto_flush_enabled()` expose core file sink policy state / `path()` 与 `auto_flush_enabled()` 可读取 file sink 的基础策略状态 - `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 是否启用及当前配置参数 - `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 快照 - `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 快照
- `reset_failure_counters()` clears the open/write/flush/rotation counters after diagnostics or recovery / `reset_failure_counters()` 可在排障或恢复后清空 open/write/flush/rotation 失败计数
- `file_sink_state_to_json(...)` / `stringify_file_sink_state(...)` and `runtime_file_state_to_json(...)` / `stringify_runtime_file_state(...)` export snapshots as JSON / `file_sink_state_to_json(...)` / `stringify_file_sink_state(...)` 与 `runtime_file_state_to_json(...)` / `stringify_runtime_file_state(...)` 可将快照直接导出为 JSON - `file_sink_state_to_json(...)` / `stringify_file_sink_state(...)` and `runtime_file_state_to_json(...)` / `stringify_runtime_file_state(...)` export snapshots as JSON / `file_sink_state_to_json(...)` / `stringify_file_sink_state(...)` 与 `runtime_file_state_to_json(...)` / `stringify_runtime_file_state(...)` 可将快照直接导出为 JSON
- `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 的基础策略 - `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 健康状态 - `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, 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 与失败计数访问器 - `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 与失败计数访问器
- `ConfiguredLogger::file_runtime_state()` also reports whether a file sink is queue-wrapped and exposes the outer queue pending/drop counters together with the inner file snapshot / `ConfiguredLogger::file_runtime_state()` 还可报告 file sink 是否被 queue 包装,并将外层 queue 的 pending/drop 计数与内层 file 快照一起返回 - `ConfiguredLogger::file_runtime_state()` also reports whether a file sink is queue-wrapped and exposes the outer queue pending/drop counters together with the inner file snapshot / `ConfiguredLogger::file_runtime_state()` 还可报告 file sink 是否被 queue 包装,并将外层 queue 的 pending/drop 计数与内层 file 快照一起返回
- `ConfiguredLogger::file_reset_failure_counters()` also clears file failure counters through the config-built control surface / `ConfiguredLogger::file_reset_failure_counters()` 也可通过配置式控制面清空 file 失败计数
- current scope is observability-first, not a full self-healing sink runtime / 当前定位仍以可观测性优先,不是完整自愈型 sink runtime - current scope is observability-first, not a full self-healing sink runtime / 当前定位仍以可观测性优先,不是完整自愈型 sink runtime
+18
View File
@@ -470,6 +470,20 @@ pub fn RuntimeSink::file_rotation_failures(self : RuntimeSink) -> Int {
} }
} }
pub fn RuntimeSink::file_reset_failure_counters(self : RuntimeSink) -> Bool {
match self {
File(sink) => {
sink.reset_failure_counters()
true
}
QueuedFile(sink) => {
sink.sink.reset_failure_counters()
true
}
_ => false
}
}
pub fn RuntimeSink::file_state(self : RuntimeSink) -> FileSinkState { pub fn RuntimeSink::file_state(self : RuntimeSink) -> FileSinkState {
match self { match self {
File(sink) => sink.state() File(sink) => sink.state()
@@ -608,6 +622,10 @@ pub fn ConfiguredLogger::file_rotation_failures(self : ConfiguredLogger) -> Int
self.sink.file_rotation_failures() self.sink.file_rotation_failures()
} }
pub fn ConfiguredLogger::file_reset_failure_counters(self : ConfiguredLogger) -> Bool {
self.sink.file_reset_failure_counters()
}
pub fn ConfiguredLogger::file_state(self : ConfiguredLogger) -> FileSinkState { pub fn ConfiguredLogger::file_state(self : ConfiguredLogger) -> FileSinkState {
self.sink.file_state() self.sink.file_state()
} }
+7
View File
@@ -213,6 +213,13 @@ pub fn FileSink::flush_failures(self : FileSink) -> Int {
self.flush_failures.val self.flush_failures.val
} }
pub fn FileSink::reset_failure_counters(self : FileSink) -> Unit {
self.open_failures.val = 0
self.write_failures.val = 0
self.flush_failures.val = 0
self.rotation_failures.val = 0
}
pub fn FileSink::state(self : FileSink) -> FileSinkState { pub fn FileSink::state(self : FileSink) -> FileSinkState {
{ {
path: self.path, path: self.path,
+2
View File
@@ -230,9 +230,11 @@ match logger.file_runtime_state() {
- `file_sink(...)` also exposes `path()` and `auto_flush_enabled()` for reading basic file-sink policy state. - `file_sink(...)` also exposes `path()` and `auto_flush_enabled()` for reading basic file-sink policy state.
- `file_sink(...)` also exposes `rotation_enabled()` and `rotation_config()` for reading whether rotation is active and which parameters are currently in effect. - `file_sink(...)` also exposes `rotation_enabled()` and `rotation_config()` for reading whether rotation is active and which parameters are currently in effect.
- `file_sink(...)` also exposes `state()` for reading a single snapshot that includes path, availability, append policy, auto-flush flag, rotation config, and all current failure counters. - `file_sink(...)` also exposes `state()` for reading a single snapshot that includes path, availability, append policy, auto-flush flag, rotation config, and all current failure counters.
- `file_sink(...)` also exposes `reset_failure_counters()` so open/write/flush/rotation failure counters can be cleared after diagnostics or recovery handling.
- `file_sink(...)` also supports `set_auto_flush(...)`, `set_rotation(...)`, and `clear_rotation()` for runtime policy updates. - `file_sink(...)` also supports `set_auto_flush(...)`, `set_rotation(...)`, and `clear_rotation()` for runtime policy updates.
- `ConfiguredLogger` built through `build_logger(...)` also exposes `file_reopen()`, `file_reopen_with_current_policy()`, `file_reopen_append()`, `file_reopen_truncate()`, `file_flush()`, `file_close()`, `file_append_mode()`, `file_path()`, `file_auto_flush()`, `file_rotation_enabled()`, `file_rotation_config()`, `file_state()`, plus `file_set_append_mode(...)`, `file_set_auto_flush(...)`, `file_set_rotation(...)`, `file_clear_rotation()`, and the corresponding file failure counters, so config-driven file logging keeps a usable control surface. - `ConfiguredLogger` built through `build_logger(...)` also exposes `file_reopen()`, `file_reopen_with_current_policy()`, `file_reopen_append()`, `file_reopen_truncate()`, `file_flush()`, `file_close()`, `file_append_mode()`, `file_path()`, `file_auto_flush()`, `file_rotation_enabled()`, `file_rotation_config()`, `file_state()`, plus `file_set_append_mode(...)`, `file_set_auto_flush(...)`, `file_set_rotation(...)`, `file_clear_rotation()`, and the corresponding file failure counters, so config-driven file logging keeps a usable control surface.
- `ConfiguredLogger` also exposes `file_runtime_state()` so queued file loggers can report both the underlying file snapshot and the outer queue backlog/drop state in one read. - `ConfiguredLogger` also exposes `file_runtime_state()` so queued file loggers can report both the underlying file snapshot and the outer queue backlog/drop state in one read.
- `ConfiguredLogger` also exposes `file_reset_failure_counters()` for clearing file failure counters through the config-built control surface.
- `file_sink_state_to_json(...)`, `stringify_file_sink_state(...)`, `runtime_file_state_to_json(...)`, and `stringify_runtime_file_state(...)` can export file and queued-file snapshots directly as JSON for diagnostics or reporting. - `file_sink_state_to_json(...)`, `stringify_file_sink_state(...)`, `runtime_file_state_to_json(...)`, and `stringify_runtime_file_state(...)` can export file and queued-file snapshots directly as JSON for diagnostics or reporting.
- `sink.text_formatter.template` currently supports fixed tokens: `{timestamp}`, `{timestamp_ms}`, `{level}`, `{target}`, `{message}`, and `{fields}`. - `sink.text_formatter.template` currently supports fixed tokens: `{timestamp}`, `{timestamp_ms}`, `{level}`, `{target}`, `{message}`, and `{fields}`.
- Config-driven sink assembly currently supports `console`, `json_console`, `text_console`, and `file`. - Config-driven sink assembly currently supports `console`, `json_console`, `text_console`, and `file`.
+1
View File
@@ -42,6 +42,7 @@ version 0.3.0
- feat: add `FileSinkState`, `FileSink::state()`, and `file_state()` helpers so file-sink runtime policy and failure counters can be read as one snapshot - feat: add `FileSinkState`, `FileSink::state()`, and `file_state()` helpers so file-sink runtime policy and failure counters can be read as one snapshot
- feat: add `RuntimeFileState` and `file_runtime_state()` so config-built queued file sinks can expose outer queue backlog/drop state together with inner file state - feat: add `RuntimeFileState` and `file_runtime_state()` so config-built queued file sinks can expose outer queue backlog/drop state together with inner file state
- feat: add JSON export helpers for `FileSinkState` and `RuntimeFileState` so runtime file snapshots can be dumped directly for diagnostics - feat: add JSON export helpers for `FileSinkState` and `RuntimeFileState` so runtime file snapshots can be dumped directly for diagnostics
- feat: add `reset_failure_counters()` / `file_reset_failure_counters()` so file failure counters can be cleared after diagnostics or recovery handling
- feat: add `SplitSink`, `split_sink(...)`, and `split_by_level(...)` for routing records into different sinks by predicate or level - feat: add `SplitSink`, `split_sink(...)`, and `split_by_level(...)` for routing records into different sinks by predicate or level
- feat: add `Logger::bind(...)` as an ergonomic context-binding alias and `fields(...)` helper for tuple-based field construction - feat: add `Logger::bind(...)` as an ergonomic context-binding alias and `fields(...)` helper for tuple-based field construction