mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
✨ Add explicit configured file flush and close helpers
This commit is contained in:
@@ -231,3 +231,43 @@ test "configured logger can reopen built file sink" {
|
||||
inspect(logger.file_open_failures(), content="2")
|
||||
}
|
||||
}
|
||||
|
||||
test "configured logger exposes file flush and close helpers" {
|
||||
let logger = build_logger(
|
||||
LoggerConfig::new(
|
||||
sink=SinkConfig::new(kind=SinkKind::File, path="config-control.log"),
|
||||
),
|
||||
)
|
||||
if logger.file_available() {
|
||||
logger.info("before flush")
|
||||
inspect(logger.file_flush(), content="true")
|
||||
inspect(logger.file_close(), content="true")
|
||||
inspect(logger.file_available(), content="false")
|
||||
inspect(logger.file_flush(), content="false")
|
||||
} else {
|
||||
inspect(logger.file_flush(), content="false")
|
||||
inspect(logger.file_close(), content="false")
|
||||
}
|
||||
}
|
||||
|
||||
test "configured queued file logger flushes queue through file helper" {
|
||||
let logger = build_logger(
|
||||
LoggerConfig::new(
|
||||
sink=SinkConfig::new(kind=SinkKind::File, path="config-queued-file.log"),
|
||||
queue=Some(QueueConfig::new(4, overflow=QueueOverflowPolicy::DropNewest)),
|
||||
),
|
||||
)
|
||||
logger.info("one")
|
||||
logger.info("two")
|
||||
if logger.file_available() {
|
||||
inspect(logger.pending_count(), content="2")
|
||||
inspect(logger.file_flush(), content="true")
|
||||
inspect(logger.pending_count(), content="0")
|
||||
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")
|
||||
inspect(logger.file_close(), content="false")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,5 +222,5 @@ test {
|
||||
- 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()` 可显式重开当前文件句柄
|
||||
- `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 and failure-counter helpers for config-built file sinks / `ConfiguredLogger` 也会为配置生成的 file sink 转发 reopen 与失败计数访问器
|
||||
- `ConfiguredLogger` also forwards file reopen, flush, close, and failure-counter helpers for config-built file sinks / `ConfiguredLogger` 也会为配置生成的 file sink 转发 reopen、flush、close 与失败计数访问器
|
||||
- current scope is observability-first, not a full self-healing sink runtime / 当前定位仍以可观测性优先,不是完整自愈型 sink runtime
|
||||
|
||||
@@ -231,6 +231,28 @@ pub fn RuntimeSink::file_reopen(self : RuntimeSink, append~ : Bool? = None) -> B
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_flush(self : RuntimeSink) -> Bool {
|
||||
match self {
|
||||
File(sink) => sink.flush()
|
||||
QueuedFile(sink) => {
|
||||
ignore(sink.flush())
|
||||
sink.sink.flush()
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_close(self : RuntimeSink) -> Bool {
|
||||
match self {
|
||||
File(sink) => sink.close()
|
||||
QueuedFile(sink) => {
|
||||
ignore(sink.flush())
|
||||
sink.sink.close()
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_open_failures(self : RuntimeSink) -> Int {
|
||||
match self {
|
||||
File(sink) => sink.open_failures()
|
||||
@@ -293,6 +315,14 @@ pub fn ConfiguredLogger::file_reopen(self : ConfiguredLogger, append~ : Bool? =
|
||||
self.sink.file_reopen(append=append)
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_flush(self : ConfiguredLogger) -> Bool {
|
||||
self.sink.file_flush()
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_close(self : ConfiguredLogger) -> Bool {
|
||||
self.sink.file_close()
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_open_failures(self : ConfiguredLogger) -> Int {
|
||||
self.sink.file_open_failures()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user