pub struct Logger { /* private fields */ }Expand description
Builder for initializing the global tracing subscriber.
Uses a fluent builder pattern to configure log level, output format,
and optional environment-based filtering before calling init.
§Examples
Minimal setup (text output at INFO level):
use tiny_tracing::Logger;
Logger::new().init().unwrap();
tiny_tracing::info!("Ready");JSON output with environment filter:
use tiny_tracing::{Logger, LogFormat, Level};
Logger::new()
.with_level(Level::DEBUG)
.with_format(LogFormat::Json)
.with_env_filter("info,my_crate=trace")
.init()
.unwrap();Implementations§
Source§impl Logger
impl Logger
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Logger with default values.
Defaults: Level::INFO, LogFormat::Text, no env filter,
file location off, target on.
Examples found in repository?
More examples
Sourcepub fn with_level(self, level: Level) -> Self
pub fn with_level(self, level: Level) -> Self
Sets the maximum log level.
Ignored if with_env_filter is also set.
Sourcepub fn with_format(self, format: LogFormat) -> Self
pub fn with_format(self, format: LogFormat) -> Self
Sets the output format.
Sourcepub fn with_env_filter(self, filter: impl Into<String>) -> Self
pub fn with_env_filter(self, filter: impl Into<String>) -> Self
Enables environment-based filtering via EnvFilter.
When set, the filter string is used instead of the static level.
Supported syntax: "info", "info,my_crate=debug", etc.
If not called, only the static with_level value applies.
Sourcepub fn with_file(self, enabled: bool) -> Self
pub fn with_file(self, enabled: bool) -> Self
Controls whether the source file name appears in log lines.
Disabled by default.
Sourcepub fn with_target(self, enabled: bool) -> Self
pub fn with_target(self, enabled: bool) -> Self
Controls whether the module path (target) appears in log lines.
Enabled by default.
Sourcepub fn init(self) -> Result<(), LoggerError>
pub fn init(self) -> Result<(), LoggerError>
Initializes the global tracing subscriber.
Consumes the builder. Must be called only once per process;
subsequent calls return LoggerError::TryInitError.
§Errors
LoggerError::InvalidEnvFilterif an env filter was set andEnvFilterrejects it.LoggerError::TryInitErrorif a global subscriber is already set.