diff --git a/README.md b/README.md index 16f8987..5c7089d 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,8 @@ if native_files_supported() { - `file_sink(...)` 还提供 `reopen()`、`open_failures()`、`write_failures()`、`flush_failures()`、`rotation_failures()`,用于基础可观测性 - `file_sink(...)` 当前还提供 `append_mode()`;`reopen(append=...)` 在显式传值时会更新后续 reopen 使用的 append 策略 - `file_sink(...)` 也可直接读取 `path()` 与 `auto_flush_enabled()` 等基础 file 策略状态 -- `build_logger(...)` 产出的 `ConfiguredLogger` 同样提供 `file_reopen()`、`file_flush()`、`file_close()`、`file_append_mode()`、`file_path()`、`file_auto_flush()` 与对应 file failure 计数访问器,便于配置式接入后继续运维控制 +- `file_sink(...)` 还提供 `rotation_enabled()` 与 `rotation_config()`,可直接查询当前 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 failure 计数访问器,便于配置式接入后继续运维控制 - `sink.text_formatter.template` 当前支持固定 token:`{timestamp}`、`{timestamp_ms}`、`{level}`、`{target}`、`{message}`、`{fields}` - 当前可由配置直接组装的 sink 类型:`console`、`json_console`、`text_console`、`file` - `queue` 会作为显式包装层附着在最终 sink 外侧;这仍然是同步 drain 模型,不是 async runtime diff --git a/bitlogger/BitLogger_test.mbt b/bitlogger/BitLogger_test.mbt index 4fb1c50..68edd4a 100644 --- a/bitlogger/BitLogger_test.mbt +++ b/bitlogger/BitLogger_test.mbt @@ -202,6 +202,7 @@ test "configured logger exposes file sink observability helpers" { kind=SinkKind::File, path="config-file.log", auto_flush=false, + rotation=Some(file_rotation(64, max_backups=3)), ), ), ) @@ -209,6 +210,14 @@ test "configured logger exposes file sink observability helpers" { inspect(logger.file_path(), content="config-file.log") inspect(logger.file_append_mode(), content="true") inspect(logger.file_auto_flush(), content="false") + inspect(logger.file_rotation_enabled(), content="true") + match logger.file_rotation_config() { + Some(rotation) => { + inspect(rotation.max_bytes, content="64") + inspect(rotation.max_backups, content="3") + } + None => inspect(false, content="true") + } inspect(logger.file_open_failures(), content=if logger.file_available() { "0" } else { "1" }) inspect(logger.file_write_failures(), content="0") inspect(logger.file_flush_failures(), content="0") @@ -216,6 +225,17 @@ test "configured logger exposes file sink observability helpers" { ignore(logger.close()) } +test "configured logger reports disabled rotation when file sink has none" { + let logger = build_logger( + LoggerConfig::new( + sink=SinkConfig::new(kind=SinkKind::File, path="config-no-rotation.log"), + ), + ) + inspect(logger.file_rotation_enabled(), content="false") + inspect(logger.file_rotation_config() is None, content="true") + ignore(logger.close()) +} + test "configured logger can reopen built file sink" { let logger = build_logger( LoggerConfig::new( diff --git a/bitlogger/BitLogger_wbtest.mbt b/bitlogger/BitLogger_wbtest.mbt index cdc93f0..37a1b80 100644 --- a/bitlogger/BitLogger_wbtest.mbt +++ b/bitlogger/BitLogger_wbtest.mbt @@ -93,6 +93,8 @@ test "file sink availability reflects backend support" { inspect(sink.is_available() == native_files_supported(), content="true") inspect(sink.append_mode(), content="true") inspect(sink.auto_flush_enabled(), content="true") + inspect(sink.rotation_enabled(), content="false") + inspect(sink.rotation_config() is None, content="true") inspect(sink.open_failures(), content=if sink.is_available() { "0" } else { "1" }) inspect(sink.write_failures(), content="0") inspect(sink.flush_failures(), content="0") @@ -109,6 +111,15 @@ test "file sink rotation config normalizes invalid inputs" { let rotation = file_rotation(0, max_backups=0) inspect(rotation.max_bytes, content="1") inspect(rotation.max_backups, content="1") + let sink = file_sink("bitlogger-rotation-config.log", rotation=Some(rotation)) + inspect(sink.rotation_enabled(), content="true") + match sink.rotation_config() { + Some(config) => { + inspect(config.max_bytes, content="1") + inspect(config.max_backups, content="1") + } + None => inspect(false, content="true") + } } test "file sink tracks rotation failures on unavailable backend" { diff --git a/bitlogger/README.mbt.md b/bitlogger/README.mbt.md index a8f5e97..35f13de 100644 --- a/bitlogger/README.mbt.md +++ b/bitlogger/README.mbt.md @@ -223,6 +223,7 @@ test { - `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 策略 - `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 是否启用及当前配置参数 - `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, and failure-counter helpers for config-built file sinks / `ConfiguredLogger` 也会为配置生成的 file sink 转发 reopen、flush、close、append-mode、path、auto-flush 与失败计数访问器 +- `ConfiguredLogger` also forwards file reopen, flush, close, append-mode, path, auto-flush, rotation-config, and failure-counter helpers for config-built file sinks / `ConfiguredLogger` 也会为配置生成的 file sink 转发 reopen、flush、close、append-mode、path、auto-flush、rotation 配置与失败计数访问器 - current scope is observability-first, not a full self-healing sink runtime / 当前定位仍以可观测性优先,不是完整自愈型 sink runtime diff --git a/bitlogger/config.mbt b/bitlogger/config.mbt index 04e8398..505e61b 100644 --- a/bitlogger/config.mbt +++ b/bitlogger/config.mbt @@ -255,6 +255,22 @@ pub fn RuntimeSink::file_auto_flush(self : RuntimeSink) -> Bool { } } +pub fn RuntimeSink::file_rotation_enabled(self : RuntimeSink) -> Bool { + match self { + File(sink) => sink.rotation_enabled() + QueuedFile(sink) => sink.sink.rotation_enabled() + _ => false + } +} + +pub fn RuntimeSink::file_rotation_config(self : RuntimeSink) -> FileRotation? { + match self { + File(sink) => sink.rotation_config() + QueuedFile(sink) => sink.sink.rotation_config() + _ => None + } +} + pub fn RuntimeSink::file_flush(self : RuntimeSink) -> Bool { match self { File(sink) => sink.flush() @@ -351,6 +367,14 @@ pub fn ConfiguredLogger::file_auto_flush(self : ConfiguredLogger) -> Bool { self.sink.file_auto_flush() } +pub fn ConfiguredLogger::file_rotation_enabled(self : ConfiguredLogger) -> Bool { + self.sink.file_rotation_enabled() +} + +pub fn ConfiguredLogger::file_rotation_config(self : ConfiguredLogger) -> FileRotation? { + self.sink.file_rotation_config() +} + pub fn ConfiguredLogger::file_flush(self : ConfiguredLogger) -> Bool { self.sink.file_flush() } diff --git a/bitlogger/sinks.mbt b/bitlogger/sinks.mbt index 3a55950..f0ba5b8 100644 --- a/bitlogger/sinks.mbt +++ b/bitlogger/sinks.mbt @@ -126,6 +126,14 @@ pub fn FileSink::auto_flush_enabled(self : FileSink) -> Bool { self.auto_flush } +pub fn FileSink::rotation_enabled(self : FileSink) -> Bool { + self.rotation is Some(_) +} + +pub fn FileSink::rotation_config(self : FileSink) -> FileRotation? { + self.rotation +} + pub fn FileSink::close(self : FileSink) -> Bool { match self.handle.val { None => false diff --git a/docs/README-en.md b/docs/README-en.md index ce24917..61cdbbb 100644 --- a/docs/README-en.md +++ b/docs/README-en.md @@ -209,7 +209,8 @@ if native_files_supported() { - `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 `path()` and `auto_flush_enabled()` for reading basic file-sink policy state. -- `ConfiguredLogger` built through `build_logger(...)` also exposes `file_reopen()`, `file_flush()`, `file_close()`, `file_append_mode()`, `file_path()`, `file_auto_flush()`, and the corresponding file failure counters, so config-driven file logging keeps a usable control surface. +- `file_sink(...)` also exposes `rotation_enabled()` and `rotation_config()` for reading whether rotation is active and which parameters are currently in effect. +- `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()`, 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}`. - 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. diff --git a/docs/changes/0.3.0.md b/docs/changes/0.3.0.md index 8a19140..be3819a 100644 --- a/docs/changes/0.3.0.md +++ b/docs/changes/0.3.0.md @@ -34,6 +34,7 @@ version 0.3.0 - feat: add explicit `file_flush()` and `file_close()` helpers for config-built file sinks, including queued file sink drain-before-close behavior - feat: make file append mode queryable via `append_mode()` / `file_append_mode()` and persist explicit `reopen(append=...)` mode updates for later reopen calls - 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 `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 @@ -52,6 +53,7 @@ version 0.3.0 - test: cover config-built file logger flush/close helpers and queued-file drain semantics - test: cover append-mode observability and reopen-mode persistence 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 split sink predicate routing and level-based routing behavior - test: cover `bind(...)` context composition and `fields(...)` helper behavior - test: add async logger lifecycle, config roundtrip, and batching/flush policy test seeds @@ -71,6 +73,7 @@ version 0.3.0 - docs: document explicit file flush/close helpers for config-built file loggers - docs: clarify append-mode observability and reopen append-policy semantics - docs: document file path and auto-flush introspection helpers +- docs: document rotation introspection helpers for direct and config-built file sinks - docs: add split sink examples for level-based routing - docs: add `bind(...)` examples for reusable context binding - docs: update root README and English README with async adapter notes and current scope