v0.1.3-pre.005

This commit is contained in:
2026-08-15 20:22:02 +02:00
parent 29660fd9f0
commit 063b24ee1c
17 changed files with 957 additions and 244 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-logging-lib/tests/runtime.rs
// version: 5
// version: 6
//! Integration tests for global initialization, takeover filtering, non-blocking outputs and hot reload.
@@ -172,33 +172,103 @@ fn global_runtime_supports_takeover_non_blocking_outputs_hot_reload_and_single_i
assert!(logging_trace_enabled());
assert!(!external_error_enabled());
exercise_concurrent_reload(&mut guard, &disabled);
let log_directory = root.join("logs");
let file_enabled = ksp_logging_lib::LoggingSettings::new(
let domain_routed = ksp_logging_lib::LoggingSettings::new(
ksp_logging_lib::LogFilterLevel::Info,
ksp_logging_lib::SpanEvents::Off,
std::option::Option::None,
std::vec![ksp_logging_lib::FileSettings::new(
"file.runtime",
std::option::Option::Some(ksp_logging_lib::ConsoleSettings::new(
true,
log_directory.as_path(),
"runtime-test.log",
ksp_logging_lib::FileRotation::Never,
ksp_logging_lib::ConsoleOutput::Stderr,
false,
ksp_logging_lib::LogFormat::Human,
ksp_logging_lib::OutputFilter::unrestricted(),
)],
ksp_logging_lib::OutputFilter::new(ksp_logging_lib::LogFilterLevel::Info, std::vec!["*".to_string()], std::vec!["logging".to_string()]),
)),
std::vec::Vec::new(),
);
let file_reload = ksp_logging_lib::reinitialize(&mut guard, &file_enabled);
let domain_reload = ksp_logging_lib::reinitialize(&mut guard, &domain_routed);
assert!(domain_reload.is_err());
assert_ne!(guard.settings(), &domain_routed);
let human_directory = root.join("human");
let compact_directory = root.join("compact");
let pretty_directory = root.join("pretty");
let json_directory = root.join("json");
let files_enabled = ksp_logging_lib::LoggingSettings::new(
ksp_logging_lib::LogFilterLevel::Trace,
ksp_logging_lib::SpanEvents::Off,
std::option::Option::None,
std::vec![
ksp_logging_lib::FileSettings::new(
"file.human.logging",
true,
human_directory.as_path(),
"human.log",
ksp_logging_lib::FileRotation::Never,
ksp_logging_lib::LogFormat::Human,
ksp_logging_lib::OutputFilter::new(ksp_logging_lib::LogFilterLevel::Info, std::vec![LOGGING_TARGET.to_string()], std::vec!["*".to_string()],),
),
ksp_logging_lib::FileSettings::new(
"file.compact.store",
true,
compact_directory.as_path(),
"compact.log",
ksp_logging_lib::FileRotation::Never,
ksp_logging_lib::LogFormat::Compact,
ksp_logging_lib::OutputFilter::new(ksp_logging_lib::LogFilterLevel::Warn, std::vec![OTHER_KSP_TARGET.to_string()], std::vec!["*".to_string()],),
),
ksp_logging_lib::FileSettings::new(
"file.pretty.error",
true,
pretty_directory.as_path(),
"pretty.log",
ksp_logging_lib::FileRotation::Never,
ksp_logging_lib::LogFormat::Pretty,
ksp_logging_lib::OutputFilter::new(ksp_logging_lib::LogFilterLevel::Error, std::vec![LOGGING_TARGET.to_string()], std::vec!["*".to_string()],),
),
ksp_logging_lib::FileSettings::new(
"file.json.logging",
true,
json_directory.as_path(),
"runtime.jsonl",
ksp_logging_lib::FileRotation::Never,
ksp_logging_lib::LogFormat::Json,
ksp_logging_lib::OutputFilter::new(ksp_logging_lib::LogFilterLevel::Trace, std::vec![LOGGING_TARGET.to_string()], std::vec!["*".to_string()],),
),
],
);
let file_reload = ksp_logging_lib::reinitialize(&mut guard, &files_enabled);
assert!(file_reload.is_ok());
ksp_logging_lib::info!(target: LOGGING_TARGET, "file \x1b[31moutput\x1b[0m marker");
ksp_logging_lib::info!(target: LOGGING_TARGET, "logging info \x1b[31mmarker\x1b[0m");
ksp_logging_lib::error!(target: LOGGING_TARGET, "logging error marker");
ksp_logging_lib::warn!(target: OTHER_KSP_TARGET, "store warning marker");
ksp_logging_lib::info!(target: OTHER_KSP_TARGET, "store info must be filtered");
tracing::error!(target: EXTERNAL_TARGET, "external marker must remain silent");
let disable_after_file = ksp_logging_lib::reinitialize(&mut guard, &disabled);
assert!(disable_after_file.is_ok());
let file_text = read_directory_text(log_directory.as_path());
assert!(file_text.contains("file output marker"));
assert!(file_text.contains(LOGGING_TARGET));
assert!(file_text.contains("runtime.rs"));
assert!(!file_text.contains("\x1b["));
assert!(!file_text.contains("external marker must remain silent"));
let human_text = read_directory_text(human_directory.as_path());
let compact_text = read_directory_text(compact_directory.as_path());
let pretty_text = read_directory_text(pretty_directory.as_path());
let json_text = read_directory_text(json_directory.as_path());
assert!(human_text.contains("logging info marker"));
assert!(human_text.contains("logging error marker"));
assert!(!human_text.contains("store warning marker"));
assert!(!human_text.contains("\x1b["));
assert!(compact_text.contains("store warning marker"));
assert!(!compact_text.contains("store info must be filtered"));
assert!(!compact_text.contains("logging info marker"));
assert!(pretty_text.contains("logging error marker"));
assert!(!pretty_text.contains("logging info marker"));
assert!(json_text.contains("logging info marker"));
assert!(json_text.contains("logging error marker"));
assert!(json_text.contains(LOGGING_TARGET));
assert!(!json_text.contains("store warning marker"));
assert!(!human_text.contains("external marker must remain silent"));
assert!(!compact_text.contains("external marker must remain silent"));
assert!(!pretty_text.contains("external marker must remain silent"));
assert!(!json_text.contains("external marker must remain silent"));
assert_eq!(guard.dropped_file_lines("file.human.logging"), std::option::Option::Some(0));
assert_eq!(guard.dropped_file_lines("file.compact.store"), std::option::Option::Some(0));
assert_eq!(guard.dropped_file_lines("file.pretty.error"), std::option::Option::Some(0));
assert_eq!(guard.dropped_file_lines("file.json.logging"), std::option::Option::Some(0));
assert_eq!(guard.dropped_file_lines("file.unknown"), std::option::Option::None);
let dropped = guard.dropped_lines();
assert_eq!(dropped.total(), dropped.console().saturating_add(dropped.file()));
let second_initialize = ksp_logging_lib::initialize(&disabled);