mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-26 09:52:31 +00:00
📝 Fix policy test and doc
This commit is contained in:
@@ -1034,6 +1034,7 @@ test "runtime sink plain variants use documented fallback counts" {
|
||||
test "runtime sink non-file variants expose documented file fallbacks" {
|
||||
let sink = RuntimeSink::Console(console_sink())
|
||||
inspect(sink.file_available(), content="false")
|
||||
inspect(sink.file_path_or_none() is None, content="true")
|
||||
inspect(sink.file_path(), content="")
|
||||
inspect(sink.file_append_mode(), content="false")
|
||||
inspect(sink.file_auto_flush(), content="false")
|
||||
@@ -1059,8 +1060,11 @@ test "runtime sink non-file variants expose documented file fallbacks" {
|
||||
inspect(sink.file_reset_policy(), content="false")
|
||||
inspect(sink.file_flush(), content="false")
|
||||
inspect(sink.file_close(), content="false")
|
||||
inspect(sink.file_policy_or_none() is None, content="true")
|
||||
inspect(sink.file_default_policy_or_none() is None, content="true")
|
||||
let policy = sink.file_policy()
|
||||
let defaults = sink.file_default_policy()
|
||||
inspect(sink.file_state_or_none() is None, content="true")
|
||||
let state = sink.file_state()
|
||||
inspect(policy.append, content="false")
|
||||
inspect(policy.auto_flush, content="false")
|
||||
@@ -1091,10 +1095,28 @@ test "runtime sink plain file helpers expose direct file state and policy" {
|
||||
),
|
||||
)
|
||||
inspect(sink.file_available() == native_files_supported(), content="true")
|
||||
match sink.file_path_or_none() {
|
||||
Some(path) => inspect(path, content="runtime-file-helpers.log")
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
inspect(sink.file_path(), content="runtime-file-helpers.log")
|
||||
inspect(sink.file_append_mode(), content="true")
|
||||
inspect(sink.file_auto_flush(), content="false")
|
||||
inspect(sink.file_rotation_enabled(), content="true")
|
||||
match sink.file_default_policy_or_none() {
|
||||
Some(policy) => {
|
||||
inspect(policy.append, content="true")
|
||||
inspect(policy.auto_flush, content="false")
|
||||
}
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
match sink.file_policy_or_none() {
|
||||
Some(policy) => {
|
||||
inspect(policy.append, content="true")
|
||||
inspect(policy.auto_flush, content="false")
|
||||
}
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
let defaults = sink.file_default_policy()
|
||||
let policy = sink.file_policy()
|
||||
inspect(defaults.append, content="true")
|
||||
@@ -1109,6 +1131,14 @@ test "runtime sink plain file helpers expose direct file state and policy" {
|
||||
}
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
match sink.file_state_or_none() {
|
||||
Some(snapshot) => {
|
||||
inspect(snapshot.path, content="runtime-file-helpers.log")
|
||||
inspect(snapshot.append, content="true")
|
||||
inspect(snapshot.auto_flush, content="false")
|
||||
}
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
let state = sink.file_state()
|
||||
inspect(state.path, content="runtime-file-helpers.log")
|
||||
inspect(state.available == sink.file_available(), content="true")
|
||||
@@ -1162,7 +1192,14 @@ test "runtime sink queued file helpers preserve queue-aware file runtime state"
|
||||
logger.info("two")
|
||||
logger.info("three")
|
||||
inspect(sink.file_available() == native_files_supported(), content="true")
|
||||
match sink.file_path_or_none() {
|
||||
Some(path) => inspect(path, content="runtime-queued-file.log")
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
inspect(sink.file_path(), content="runtime-queued-file.log")
|
||||
inspect(sink.file_policy_or_none() is None, content="false")
|
||||
inspect(sink.file_default_policy_or_none() is None, content="false")
|
||||
inspect(sink.file_state_or_none() is None, content="false")
|
||||
inspect(sink.pending_count(), content="2")
|
||||
inspect(sink.dropped_count(), content="1")
|
||||
match sink.file_runtime_state() {
|
||||
@@ -2034,6 +2071,10 @@ 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_path_or_none() is None, content="true")
|
||||
inspect(logger.file_policy_or_none() is None, content="true")
|
||||
inspect(logger.file_default_policy_or_none() is None, content="true")
|
||||
inspect(logger.file_state_or_none() is None, content="true")
|
||||
inspect(logger.file_runtime_state() is None, content="true")
|
||||
}
|
||||
|
||||
@@ -2045,6 +2086,13 @@ test "configured file logger mirrors backend file capability" {
|
||||
),
|
||||
)
|
||||
inspect(logger.file_available() == native_files_supported(), content="true")
|
||||
match logger.file_path_or_none() {
|
||||
Some(path) => inspect(path, content="config-capability.log")
|
||||
None => inspect(false, content="true")
|
||||
}
|
||||
inspect(logger.file_policy_or_none() is None, content="false")
|
||||
inspect(logger.file_default_policy_or_none() is None, content="false")
|
||||
inspect(logger.file_state_or_none() is None, content="false")
|
||||
if logger.file_available() {
|
||||
inspect(logger.file_state().available, content="true")
|
||||
ignore(logger.close())
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
///|
|
||||
fn runtime_file_sink_internal(sink : RuntimeSink) -> FileSink? {
|
||||
match sink {
|
||||
File(sink) => Some(sink)
|
||||
QueuedFile(sink) => Some(sink.sink)
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeSink::file_available(self : RuntimeSink) -> Bool {
|
||||
match self {
|
||||
@@ -73,13 +82,14 @@ pub fn RuntimeSink::file_set_append_mode(
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeSink::file_path_or_none(self : RuntimeSink) -> String? {
|
||||
runtime_file_sink_internal(self).map(fn(sink) { sink.path() })
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeSink::file_path(self : RuntimeSink) -> String {
|
||||
match self {
|
||||
File(sink) => sink.path()
|
||||
QueuedFile(sink) => sink.sink.path()
|
||||
_ => ""
|
||||
}
|
||||
self.file_path_or_none().unwrap_or("")
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -268,22 +278,30 @@ pub fn RuntimeSink::file_reset_policy(self : RuntimeSink) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeSink::file_policy_or_none(self : RuntimeSink) -> FileSinkPolicy? {
|
||||
runtime_file_sink_internal(self).map(fn(sink) { sink.policy() })
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeSink::file_policy(self : RuntimeSink) -> FileSinkPolicy {
|
||||
match self {
|
||||
File(sink) => sink.policy()
|
||||
QueuedFile(sink) => sink.sink.policy()
|
||||
_ => FileSinkPolicy::new(append=false, auto_flush=false, rotation=None)
|
||||
}
|
||||
self.file_policy_or_none().unwrap_or(
|
||||
FileSinkPolicy::new(append=false, auto_flush=false, rotation=None),
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeSink::file_default_policy_or_none(
|
||||
self : RuntimeSink,
|
||||
) -> FileSinkPolicy? {
|
||||
runtime_file_sink_internal(self).map(fn(sink) { sink.default_policy() })
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeSink::file_default_policy(self : RuntimeSink) -> FileSinkPolicy {
|
||||
match self {
|
||||
File(sink) => sink.default_policy()
|
||||
QueuedFile(sink) => sink.sink.default_policy()
|
||||
_ => FileSinkPolicy::new(append=false, auto_flush=false, rotation=None)
|
||||
}
|
||||
self.file_default_policy_or_none().unwrap_or(
|
||||
FileSinkPolicy::new(append=false, auto_flush=false, rotation=None),
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -295,24 +313,26 @@ pub fn RuntimeSink::file_policy_matches_default(self : RuntimeSink) -> Bool {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeSink::file_state_or_none(self : RuntimeSink) -> FileSinkState? {
|
||||
runtime_file_sink_internal(self).map(fn(sink) { sink.state() })
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn RuntimeSink::file_state(self : RuntimeSink) -> FileSinkState {
|
||||
match self {
|
||||
File(sink) => sink.state()
|
||||
QueuedFile(sink) => sink.sink.state()
|
||||
_ =>
|
||||
FileSinkState::new(
|
||||
"",
|
||||
available=false,
|
||||
append=false,
|
||||
auto_flush=false,
|
||||
rotation=None,
|
||||
open_failures=0,
|
||||
write_failures=0,
|
||||
flush_failures=0,
|
||||
rotation_failures=0,
|
||||
)
|
||||
}
|
||||
self.file_state_or_none().unwrap_or(
|
||||
FileSinkState::new(
|
||||
"",
|
||||
available=false,
|
||||
append=false,
|
||||
auto_flush=false,
|
||||
rotation=None,
|
||||
open_failures=0,
|
||||
write_failures=0,
|
||||
flush_failures=0,
|
||||
rotation_failures=0,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -375,6 +395,11 @@ pub fn ConfiguredLogger::file_set_append_mode(
|
||||
self.sink.file_set_append_mode(append)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ConfiguredLogger::file_path_or_none(self : ConfiguredLogger) -> String? {
|
||||
self.sink.file_path_or_none()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ConfiguredLogger::file_path(self : ConfiguredLogger) -> String {
|
||||
self.sink.file_path()
|
||||
@@ -468,11 +493,25 @@ pub fn ConfiguredLogger::file_reset_policy(self : ConfiguredLogger) -> Bool {
|
||||
self.sink.file_reset_policy()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ConfiguredLogger::file_policy_or_none(
|
||||
self : ConfiguredLogger,
|
||||
) -> FileSinkPolicy? {
|
||||
self.sink.file_policy_or_none()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ConfiguredLogger::file_policy(self : ConfiguredLogger) -> FileSinkPolicy {
|
||||
self.sink.file_policy()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ConfiguredLogger::file_default_policy_or_none(
|
||||
self : ConfiguredLogger,
|
||||
) -> FileSinkPolicy? {
|
||||
self.sink.file_default_policy_or_none()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ConfiguredLogger::file_default_policy(
|
||||
self : ConfiguredLogger,
|
||||
@@ -487,6 +526,13 @@ pub fn ConfiguredLogger::file_policy_matches_default(
|
||||
self.sink.file_policy_matches_default()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ConfiguredLogger::file_state_or_none(
|
||||
self : ConfiguredLogger,
|
||||
) -> FileSinkState? {
|
||||
self.sink.file_state_or_none()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ConfiguredLogger::file_state(self : ConfiguredLogger) -> FileSinkState {
|
||||
self.sink.file_state()
|
||||
|
||||
Reference in New Issue
Block a user