mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 15:42:25 +00:00
✨ Forward file sink helpers through configured logger
This commit is contained in:
@@ -194,3 +194,40 @@ test "configured logger reports dropped_count for bounded queue" {
|
||||
inspect(logger.dropped_count(), content="2")
|
||||
inspect(logger.flush(), content="2")
|
||||
}
|
||||
|
||||
test "configured logger exposes file sink observability helpers" {
|
||||
let logger = build_logger(
|
||||
LoggerConfig::new(
|
||||
sink=SinkConfig::new(kind=SinkKind::File, path="config-file.log"),
|
||||
),
|
||||
)
|
||||
inspect(logger.file_available() == native_files_supported(), 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")
|
||||
inspect(logger.file_rotation_failures(), content="0")
|
||||
ignore(logger.close())
|
||||
}
|
||||
|
||||
test "configured logger can reopen built file sink" {
|
||||
let logger = build_logger(
|
||||
LoggerConfig::new(
|
||||
sink=SinkConfig::new(kind=SinkKind::File, path="config-reopen.log"),
|
||||
),
|
||||
)
|
||||
if logger.file_available() {
|
||||
inspect(logger.close(), content="true")
|
||||
inspect(logger.file_reopen(), content="true")
|
||||
inspect(logger.file_available(), content="true")
|
||||
inspect(logger.file_open_failures(), content="0")
|
||||
logger.info("reopened from config")
|
||||
inspect(logger.file_write_failures(), content="0")
|
||||
inspect(logger.close(), content="true")
|
||||
} else {
|
||||
inspect(logger.file_open_failures(), content="1")
|
||||
logger.info("dropped")
|
||||
inspect(logger.file_write_failures(), content="1")
|
||||
inspect(logger.file_reopen(), content="false")
|
||||
inspect(logger.file_open_failures(), content="2")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,4 +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 与失败计数访问器
|
||||
- current scope is observability-first, not a full self-healing sink runtime / 当前定位仍以可观测性优先,不是完整自愈型 sink runtime
|
||||
|
||||
@@ -223,6 +223,46 @@ pub fn RuntimeSink::file_available(self : RuntimeSink) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_reopen(self : RuntimeSink, append~ : Bool? = None) -> Bool {
|
||||
match self {
|
||||
File(sink) => sink.reopen(append=append)
|
||||
QueuedFile(sink) => sink.sink.reopen(append=append)
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_open_failures(self : RuntimeSink) -> Int {
|
||||
match self {
|
||||
File(sink) => sink.open_failures()
|
||||
QueuedFile(sink) => sink.sink.open_failures()
|
||||
_ => 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_write_failures(self : RuntimeSink) -> Int {
|
||||
match self {
|
||||
File(sink) => sink.write_failures()
|
||||
QueuedFile(sink) => sink.sink.write_failures()
|
||||
_ => 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_flush_failures(self : RuntimeSink) -> Int {
|
||||
match self {
|
||||
File(sink) => sink.flush_failures()
|
||||
QueuedFile(sink) => sink.sink.flush_failures()
|
||||
_ => 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn RuntimeSink::file_rotation_failures(self : RuntimeSink) -> Int {
|
||||
match self {
|
||||
File(sink) => sink.rotation_failures()
|
||||
QueuedFile(sink) => sink.sink.rotation_failures()
|
||||
_ => 0
|
||||
}
|
||||
}
|
||||
|
||||
pub type ConfiguredLogger = Logger[RuntimeSink]
|
||||
|
||||
pub fn ConfiguredLogger::flush(self : ConfiguredLogger) -> Int {
|
||||
@@ -249,6 +289,26 @@ pub fn ConfiguredLogger::file_available(self : ConfiguredLogger) -> Bool {
|
||||
self.sink.file_available()
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_reopen(self : ConfiguredLogger, append~ : Bool? = None) -> Bool {
|
||||
self.sink.file_reopen(append=append)
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_open_failures(self : ConfiguredLogger) -> Int {
|
||||
self.sink.file_open_failures()
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_write_failures(self : ConfiguredLogger) -> Int {
|
||||
self.sink.file_write_failures()
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_flush_failures(self : ConfiguredLogger) -> Int {
|
||||
self.sink.file_flush_failures()
|
||||
}
|
||||
|
||||
pub fn ConfiguredLogger::file_rotation_failures(self : ConfiguredLogger) -> Int {
|
||||
self.sink.file_rotation_failures()
|
||||
}
|
||||
|
||||
fn expect_object(
|
||||
value : @json_parser.JsonValue,
|
||||
context : String,
|
||||
|
||||
Reference in New Issue
Block a user