Add explicit append policy setter

This commit is contained in:
Nanaloveyuki
2026-05-10 12:49:08 +08:00
parent a71471ffb0
commit 0a7af44f06
8 changed files with 41 additions and 3 deletions
+2 -1
View File
@@ -223,10 +223,11 @@ if native_files_supported() {
- `sink.rotation` 当前支持 `max_bytes``max_backups`,提供基础 size-based rotation 和 backup retention - `sink.rotation` 当前支持 `max_bytes``max_backups`,提供基础 size-based rotation 和 backup retention
- `file_sink(...)` 还提供 `reopen()``open_failures()``write_failures()``flush_failures()``rotation_failures()`,用于基础可观测性 - `file_sink(...)` 还提供 `reopen()``open_failures()``write_failures()``flush_failures()``rotation_failures()`,用于基础可观测性
- `file_sink(...)` 当前还提供 `append_mode()``reopen(append=...)` 在显式传值时会更新后续 reopen 使用的 append 策略 - `file_sink(...)` 当前还提供 `append_mode()``reopen(append=...)` 在显式传值时会更新后续 reopen 使用的 append 策略
- `file_sink(...)` 也支持 `set_append_mode(...)`,用于显式修改后续 reopen 将使用的 append 策略
- `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(...)` 也支持 `set_auto_flush(...)``set_rotation(...)``clear_rotation()`,可在运行期调整基础写出策略 - `file_sink(...)` 也支持 `set_auto_flush(...)``set_rotation(...)``clear_rotation()`,可在运行期调整基础写出策略
- `build_logger(...)` 产出的 `ConfiguredLogger` 同样提供 `file_reopen()``file_flush()``file_close()``file_append_mode()``file_path()``file_auto_flush()``file_rotation_enabled()``file_rotation_config()`,以及 `file_set_auto_flush(...)``file_set_rotation(...)``file_clear_rotation()` 与对应 file failure 计数访问器,便于配置式接入后继续运维控制 - `build_logger(...)` 产出的 `ConfiguredLogger` 同样提供 `file_reopen()``file_flush()``file_close()``file_append_mode()``file_path()``file_auto_flush()``file_rotation_enabled()``file_rotation_config()`,以及 `file_set_append_mode(...)``file_set_auto_flush(...)``file_set_rotation(...)``file_clear_rotation()` 与对应 file failure 计数访问器,便于配置式接入后继续运维控制
- `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`
- `queue` 会作为显式包装层附着在最终 sink 外侧;这仍然是同步 drain 模型,不是 async runtime - `queue` 会作为显式包装层附着在最终 sink 外侧;这仍然是同步 drain 模型,不是 async runtime
+5
View File
@@ -243,8 +243,11 @@ test "configured logger file setters update file sink policy state" {
queue=Some(QueueConfig::new(2, overflow=QueueOverflowPolicy::DropNewest)), queue=Some(QueueConfig::new(2, overflow=QueueOverflowPolicy::DropNewest)),
), ),
) )
inspect(logger.file_append_mode(), content="true")
inspect(logger.file_auto_flush(), content="true") inspect(logger.file_auto_flush(), content="true")
inspect(logger.file_rotation_enabled(), content="false") inspect(logger.file_rotation_enabled(), content="false")
inspect(logger.file_set_append_mode(false), content="true")
inspect(logger.file_append_mode(), content="false")
inspect(logger.file_set_auto_flush(false), content="true") inspect(logger.file_set_auto_flush(false), content="true")
inspect(logger.file_auto_flush(), content="false") inspect(logger.file_auto_flush(), content="false")
inspect(logger.file_set_rotation(Some(file_rotation(48, max_backups=4))), content="true") inspect(logger.file_set_rotation(Some(file_rotation(48, max_backups=4))), content="true")
@@ -259,6 +262,8 @@ test "configured logger file setters update file sink policy state" {
inspect(logger.file_clear_rotation(), content="true") inspect(logger.file_clear_rotation(), content="true")
inspect(logger.file_rotation_enabled(), content="false") inspect(logger.file_rotation_enabled(), content="false")
inspect(logger.file_rotation_config() is None, content="true") 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")
ignore(logger.close()) ignore(logger.close())
} }
+5
View File
@@ -124,8 +124,11 @@ test "file sink rotation config normalizes invalid inputs" {
test "file sink setters update auto flush and rotation state" { test "file sink setters update auto flush and rotation state" {
let sink = file_sink("bitlogger-setters.log") let sink = file_sink("bitlogger-setters.log")
inspect(sink.append_mode(), content="true")
inspect(sink.auto_flush_enabled(), content="true") inspect(sink.auto_flush_enabled(), content="true")
inspect(sink.rotation_enabled(), content="false") inspect(sink.rotation_enabled(), content="false")
sink.set_append_mode(false)
inspect(sink.append_mode(), content="false")
sink.set_auto_flush(false) sink.set_auto_flush(false)
inspect(sink.auto_flush_enabled(), content="false") inspect(sink.auto_flush_enabled(), content="false")
sink.set_rotation(Some(file_rotation(32, max_backups=2))) sink.set_rotation(Some(file_rotation(32, max_backups=2)))
@@ -140,6 +143,8 @@ test "file sink setters update auto flush and rotation state" {
sink.clear_rotation() sink.clear_rotation()
inspect(sink.rotation_enabled(), content="false") inspect(sink.rotation_enabled(), content="false")
inspect(sink.rotation_config() is None, content="true") 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")
} }
test "file sink tracks rotation failures on unavailable backend" { test "file sink tracks rotation failures on unavailable backend" {
+2 -1
View File
@@ -222,9 +222,10 @@ test {
- JSON config uses `sink.rotation.max_bytes` and `sink.rotation.max_backups` / JSON 配置使用 `sink.rotation.max_bytes` 与 `sink.rotation.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 / `FileSink::reopen()` 可显式重开当前文件句柄
- `append_mode()` exposes the current append policy, and `reopen(append=...)` updates that policy for later reopen calls / `append_mode()` 可读取当前 append 策略,`reopen(append=...)` 会更新后续 reopen 复用的 append 策略 - `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 的基础策略状态 - `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 是否启用及当前配置参数
- `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, setter, and failure-counter helpers for config-built file sinks / `ConfiguredLogger` 也会为配置生成的 file sink 转发 reopen、flush、close、append-mode、path、auto-flush、rotation 配置、setter 与失败计数访问器 - `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 与失败计数访问器
- 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
@@ -239,6 +239,20 @@ pub fn RuntimeSink::file_append_mode(self : RuntimeSink) -> Bool {
} }
} }
pub fn RuntimeSink::file_set_append_mode(self : RuntimeSink, append : Bool) -> Bool {
match self {
File(sink) => {
sink.set_append_mode(append)
true
}
QueuedFile(sink) => {
sink.sink.set_append_mode(append)
true
}
_ => false
}
}
pub fn RuntimeSink::file_path(self : RuntimeSink) -> String { pub fn RuntimeSink::file_path(self : RuntimeSink) -> String {
match self { match self {
File(sink) => sink.path() File(sink) => sink.path()
@@ -401,6 +415,10 @@ pub fn ConfiguredLogger::file_append_mode(self : ConfiguredLogger) -> Bool {
self.sink.file_append_mode() self.sink.file_append_mode()
} }
pub fn ConfiguredLogger::file_set_append_mode(self : ConfiguredLogger, append : Bool) -> Bool {
self.sink.file_set_append_mode(append)
}
pub fn ConfiguredLogger::file_path(self : ConfiguredLogger) -> String { pub fn ConfiguredLogger::file_path(self : ConfiguredLogger) -> String {
self.sink.file_path() self.sink.file_path()
} }
+4
View File
@@ -118,6 +118,10 @@ pub fn FileSink::append_mode(self : FileSink) -> Bool {
self.append.val self.append.val
} }
pub fn FileSink::set_append_mode(self : FileSink, append : Bool) -> Unit {
self.append.val = append
}
pub fn FileSink::path(self : FileSink) -> String { pub fn FileSink::path(self : FileSink) -> String {
self.path self.path
} }
+2 -1
View File
@@ -208,10 +208,11 @@ if native_files_supported() {
- `sink.rotation` currently supports `max_bytes` and `max_backups` for basic size-based rotation and backup retention. - `sink.rotation` currently supports `max_bytes` and `max_backups` for basic size-based rotation and backup retention.
- `file_sink(...)` also exposes `reopen()`, `open_failures()`, `write_failures()`, `flush_failures()`, and `rotation_failures()` for basic observability. - `file_sink(...)` also exposes `reopen()`, `open_failures()`, `write_failures()`, `flush_failures()`, and `rotation_failures()` for basic observability.
- `file_sink(...)` also exposes `append_mode()`. Passing `append=...` to `reopen(...)` updates the current append policy used by later reopen calls. - `file_sink(...)` also exposes `append_mode()`. Passing `append=...` to `reopen(...)` updates the current append policy used by later reopen calls.
- `file_sink(...)` also supports `set_append_mode(...)` for explicitly changing the append policy that later reopen calls will use.
- `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 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_flush()`, `file_close()`, `file_append_mode()`, `file_path()`, `file_auto_flush()`, `file_rotation_enabled()`, `file_rotation_config()`, plus `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_flush()`, `file_close()`, `file_append_mode()`, `file_path()`, `file_auto_flush()`, `file_rotation_enabled()`, `file_rotation_config()`, 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.
- `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`.
- `queue` remains a synchronous bounded wrapper around the final sink, not an async runtime. - `queue` remains a synchronous bounded wrapper around the final sink, not an async runtime.
+3
View File
@@ -36,6 +36,7 @@ version 0.3.0
- feat: add `path()` / `auto_flush_enabled()` on `FileSink` and `file_path()` / `file_auto_flush()` on `ConfiguredLogger` for basic file-policy introspection - feat: add `path()` / `auto_flush_enabled()` on `FileSink` and `file_path()` / `file_auto_flush()` on `ConfiguredLogger` for basic file-policy introspection
- feat: add `rotation_enabled()` / `rotation_config()` on `FileSink` and `file_rotation_enabled()` / `file_rotation_config()` on `ConfiguredLogger` for rotation-policy introspection - feat: add `rotation_enabled()` / `rotation_config()` on `FileSink` and `file_rotation_enabled()` / `file_rotation_config()` on `ConfiguredLogger` for rotation-policy introspection
- feat: add runtime file-policy mutators `set_auto_flush(...)`, `set_rotation(...)`, `clear_rotation()` and corresponding configured-logger forwarding helpers - feat: add runtime file-policy mutators `set_auto_flush(...)`, `set_rotation(...)`, `clear_rotation()` and corresponding configured-logger forwarding helpers
- feat: add explicit append-policy setter `set_append_mode(...)` / `file_set_append_mode(...)` so append strategy can be updated without piggybacking on `reopen(...)`
- 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
@@ -56,6 +57,7 @@ version 0.3.0
- test: cover path and auto-flush introspection for direct and config-built file sinks - test: cover path and auto-flush introspection for direct and config-built file sinks
- test: cover rotation introspection for direct and config-built file sinks with and without configured rotation - test: cover rotation introspection for direct and config-built file sinks with and without configured rotation
- test: cover runtime auto-flush and rotation policy mutation for direct and config-built file sinks - test: cover runtime auto-flush and rotation policy mutation for direct and config-built file sinks
- test: cover append-policy setter behavior and confirm subsequent reopen calls inherit the updated append mode
- test: cover split sink predicate routing and level-based routing behavior - test: cover split sink predicate routing and level-based routing behavior
- test: cover `bind(...)` context composition and `fields(...)` helper behavior - test: cover `bind(...)` context composition and `fields(...)` helper behavior
- test: add async logger lifecycle, config roundtrip, and batching/flush policy test seeds - test: add async logger lifecycle, config roundtrip, and batching/flush policy test seeds
@@ -77,6 +79,7 @@ version 0.3.0
- docs: document file path and auto-flush introspection helpers - docs: document file path and auto-flush introspection helpers
- docs: document rotation introspection helpers for direct and config-built file sinks - docs: document rotation introspection helpers for direct and config-built file sinks
- docs: document runtime file-policy setter helpers for direct and config-built file sinks - docs: document runtime file-policy setter helpers for direct and config-built file sinks
- docs: clarify explicit append-policy setter semantics for direct and config-built file sinks
- docs: add split sink examples for level-based routing - docs: add split sink examples for level-based routing
- docs: add `bind(...)` examples for reusable context binding - docs: add `bind(...)` examples for reusable context binding
- docs: update root README and English README with async adapter notes and current scope - docs: update root README and English README with async adapter notes and current scope