mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 23:52:27 +00:00
✨ Clarify application and library logger entries
This commit is contained in:
@@ -824,3 +824,31 @@ test "library logger can be parsed and built from config text" {
|
||||
inspect(logger.is_enabled(Level::Info), content="false")
|
||||
inspect(full.target, content="lib.json")
|
||||
}
|
||||
|
||||
test "configured logger can project to library logger" {
|
||||
let configured = build_logger(
|
||||
LoggerConfig::new(min_level=Level::Warn, target="lib.projected"),
|
||||
)
|
||||
let logger = configured.to_library_logger()
|
||||
inspect(logger.is_enabled(Level::Error), content="true")
|
||||
inspect(logger.is_enabled(Level::Info), content="false")
|
||||
inspect(logger.to_logger().target, content="lib.projected")
|
||||
}
|
||||
|
||||
test "application logger aliases configured runtime entry" {
|
||||
let logger = build_application_logger(
|
||||
LoggerConfig::new(min_level=Level::Warn, target="app.runtime"),
|
||||
)
|
||||
inspect(logger.is_enabled(Level::Error), content="true")
|
||||
inspect(logger.is_enabled(Level::Info), content="false")
|
||||
inspect(logger.target, content="app.runtime")
|
||||
}
|
||||
|
||||
test "application logger can be built from config text" {
|
||||
let logger = parse_and_build_application_logger(
|
||||
"{\"min_level\":\"warn\",\"target\":\"app.json\",\"sink\":{\"kind\":\"console\"}}",
|
||||
)
|
||||
inspect(logger.is_enabled(Level::Error), content="true")
|
||||
inspect(logger.is_enabled(Level::Info), content="false")
|
||||
inspect(logger.target, content="app.json")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
pub type ApplicationLogger = ConfiguredLogger
|
||||
|
||||
pub fn build_application_logger(config : LoggerConfig) -> ApplicationLogger {
|
||||
build_logger(config)
|
||||
}
|
||||
|
||||
pub fn parse_and_build_application_logger(
|
||||
input : String,
|
||||
) -> ApplicationLogger raise ConfigError {
|
||||
parse_and_build_logger(input)
|
||||
}
|
||||
@@ -2,10 +2,14 @@ pub struct LibraryLogger[S] {
|
||||
inner : Logger[S]
|
||||
}
|
||||
|
||||
pub fn[S] library_logger(logger : Logger[S]) -> LibraryLogger[S] {
|
||||
fn[S] library_logger(logger : Logger[S]) -> LibraryLogger[S] {
|
||||
{ inner: logger }
|
||||
}
|
||||
|
||||
pub fn[S] Logger::to_library_logger(self : Logger[S]) -> LibraryLogger[S] {
|
||||
library_logger(self)
|
||||
}
|
||||
|
||||
pub fn[S] LibraryLogger::new(
|
||||
sink : S,
|
||||
min_level~ : Level = Level::Info,
|
||||
@@ -18,7 +22,7 @@ pub fn[S] LibraryLogger::to_logger(self : LibraryLogger[S]) -> Logger[S] {
|
||||
self.inner
|
||||
}
|
||||
|
||||
pub fn configured_library_logger(logger : ConfiguredLogger) -> LibraryLogger[RuntimeSink] {
|
||||
fn configured_library_logger(logger : ConfiguredLogger) -> LibraryLogger[RuntimeSink] {
|
||||
library_logger(logger)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user