mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
✨ Add queued file runtime state snapshots
This commit is contained in:
@@ -207,6 +207,7 @@ test "configured logger exposes file sink observability helpers" {
|
||||
),
|
||||
)
|
||||
let state = logger.file_state()
|
||||
let runtime_state = logger.file_runtime_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")
|
||||
@@ -215,6 +216,15 @@ test "configured logger exposes file sink observability helpers" {
|
||||
inspect(state.auto_flush == logger.file_auto_flush(), content="true")
|
||||
inspect(logger.file_append_mode(), content="true")
|
||||
inspect(logger.file_auto_flush(), content="false")
|
||||
match runtime_state {
|
||||
Some(snapshot) => {
|
||||
inspect(snapshot.queued, content="false")
|
||||
inspect(snapshot.pending_count, content="0")
|
||||
inspect(snapshot.dropped_count, content="0")
|
||||
inspect(snapshot.file.path, content="config-file.log")
|
||||
}
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
inspect(logger.file_rotation_enabled(), content="true")
|
||||
match logger.file_rotation_config() {
|
||||
Some(rotation) => {
|
||||
@@ -238,9 +248,20 @@ test "configured logger reports disabled rotation when file sink has none" {
|
||||
)
|
||||
inspect(logger.file_rotation_enabled(), content="false")
|
||||
inspect(logger.file_rotation_config() is None, content="true")
|
||||
match logger.file_runtime_state() {
|
||||
Some(snapshot) => inspect(snapshot.queued, content="false")
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
ignore(logger.close())
|
||||
}
|
||||
|
||||
test "configured non-file logger has no file runtime state" {
|
||||
let logger = build_logger(
|
||||
LoggerConfig::new(sink=SinkConfig::new(kind=SinkKind::Console)),
|
||||
)
|
||||
inspect(logger.file_runtime_state() is None, content="true")
|
||||
}
|
||||
|
||||
test "configured logger file setters update file sink policy state" {
|
||||
let logger = build_logger(
|
||||
LoggerConfig::new(
|
||||
@@ -343,15 +364,31 @@ test "configured queued file logger flushes queue through file helper" {
|
||||
)
|
||||
logger.info("one")
|
||||
logger.info("two")
|
||||
match logger.file_runtime_state() {
|
||||
Some(snapshot) => {
|
||||
inspect(snapshot.queued, content="true")
|
||||
inspect(snapshot.pending_count, content="2")
|
||||
inspect(snapshot.dropped_count, content="0")
|
||||
}
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
if logger.file_available() {
|
||||
inspect(logger.pending_count(), content="2")
|
||||
inspect(logger.file_flush(), content="true")
|
||||
inspect(logger.pending_count(), content="0")
|
||||
match logger.file_runtime_state() {
|
||||
Some(snapshot) => inspect(snapshot.pending_count, content="0")
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
inspect(logger.file_close(), content="true")
|
||||
} else {
|
||||
inspect(logger.pending_count(), content="2")
|
||||
inspect(logger.file_flush(), content="false")
|
||||
inspect(logger.pending_count(), content="0")
|
||||
match logger.file_runtime_state() {
|
||||
Some(snapshot) => inspect(snapshot.pending_count, content="0")
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
inspect(logger.file_close(), content="false")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,4 +229,5 @@ test {
|
||||
- `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, 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 快照一起返回
|
||||
- current scope is observability-first, not a full self-healing sink runtime / 当前定位仍以可观测性优先,不是完整自愈型 sink runtime
|
||||
|
||||
@@ -137,6 +137,13 @@ pub(all) enum RuntimeSink {
|
||||
QueuedFile(QueuedSink[FileSink])
|
||||
}
|
||||
|
||||
pub struct RuntimeFileState {
|
||||
file : FileSinkState
|
||||
queued : Bool
|
||||
pending_count : Int
|
||||
dropped_count : Int
|
||||
}
|
||||
|
||||
pub impl Sink for RuntimeSink with write(self, rec) {
|
||||
match self {
|
||||
Console(sink) => sink.write(rec)
|
||||
@@ -423,6 +430,24 @@ pub fn RuntimeSink::file_state(self : RuntimeSink) -> FileSinkState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_runtime_state(self : RuntimeSink) -> RuntimeFileState? {
|
||||
match self {
|
||||
File(sink) => Some({
|
||||
file: sink.state(),
|
||||
queued: false,
|
||||
pending_count: 0,
|
||||
dropped_count: 0,
|
||||
})
|
||||
QueuedFile(sink) => Some({
|
||||
file: sink.sink.state(),
|
||||
queued: true,
|
||||
pending_count: sink.pending_count(),
|
||||
dropped_count: sink.dropped_count(),
|
||||
})
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
pub type ConfiguredLogger = Logger[RuntimeSink]
|
||||
|
||||
pub fn ConfiguredLogger::flush(self : ConfiguredLogger) -> Int {
|
||||
@@ -532,6 +557,10 @@ pub fn ConfiguredLogger::file_state(self : ConfiguredLogger) -> FileSinkState {
|
||||
self.sink.file_state()
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_runtime_state(self : ConfiguredLogger) -> RuntimeFileState? {
|
||||
self.sink.file_runtime_state()
|
||||
}
|
||||
|
||||
fn expect_object(
|
||||
value : @json_parser.JsonValue,
|
||||
context : String,
|
||||
|
||||
Reference in New Issue
Block a user