pub struct LoggerBuilder { /* private fields */ }std only.Expand description
Builder for Logger. Construct with Logger::builder.
The builder is not generic over a format. Each call that installs
a sink (Self::with_sink, Self::stdout, Self::stderr,
Self::writer, or one of the format-specific shortcuts) carries
its own format.
Implementations§
Source§impl LoggerBuilder
impl LoggerBuilder
Sourcepub fn target_level(self, target: impl Into<String>, level: Level) -> Self
pub fn target_level(self, target: impl Into<String>, level: Level) -> Self
Add a per-target filter override. See Filter::with_rule.
Sourcepub fn filter_directive(self, directive: &str) -> Self
pub fn filter_directive(self, directive: &str) -> Self
Parse directive and replace the filter. Silently retains the
previous filter on parse error; use Filter::parse up front
if you need to surface the error.
Sourcepub fn no_timestamps(self) -> Self
pub fn no_timestamps(self) -> Self
Disable timestamp capture. By default the logger records a
timestamp on every record using std::time::SystemTime.
Sourcepub fn no_context(self) -> Self
pub fn no_context(self) -> Self
Disable thread-local context capture.
Sourcepub fn with_default_field<'a, V: Into<Value<'a>>>(
self,
key: impl Into<String>,
value: V,
) -> Self
pub fn with_default_field<'a, V: Into<Value<'a>>>( self, key: impl Into<String>, value: V, ) -> Self
Attach a field that the logger emits on every record. Useful
for service-level identifiers like service_name or version.
Sourcepub fn on_error(self, handler: Arc<dyn Fn(&Error) + Send + Sync>) -> Self
pub fn on_error(self, handler: Arc<dyn Fn(&Error) + Send + Sync>) -> Self
Install a callback invoked when a sink returns an error.
Sourcepub fn with_sink(self, sink: impl Sink + 'static) -> Self
pub fn with_sink(self, sink: impl Sink + 'static) -> Self
Install a sink directly. Use this when you have a pre-built
sink (typical for crate::sink::FileSink which is fallible
to open).
Sourcepub fn writer<W, F>(self, writer: W, format: F) -> Self
pub fn writer<W, F>(self, writer: W, format: F) -> Self
Install a sink that writes to writer with format.
Sourcepub fn build(self) -> Logger
pub fn build(self) -> Logger
Finish configuration. Panics if no sink has been installed.
§Panics
Panics if Self::with_sink, Self::stdout, Self::stderr,
Self::writer, or one of the format shortcuts has not been
called. Building a logger without a destination is almost
certainly a programmer error.
Source§impl LoggerBuilder
impl LoggerBuilder
Sourcepub fn stdout_json(self) -> Self
Available on crate feature json only.
pub fn stdout_json(self) -> Self
json only.Install a stdout sink with the default JSON format.
Sourcepub fn stderr_json(self) -> Self
Available on crate feature json only.
pub fn stderr_json(self) -> Self
json only.Install a stderr sink with the default JSON format.
Source§impl LoggerBuilder
impl LoggerBuilder
Sourcepub fn stdout_logfmt(self) -> Self
Available on crate feature logfmt only.
pub fn stdout_logfmt(self) -> Self
logfmt only.Install a stdout sink with the logfmt format.
Sourcepub fn stderr_logfmt(self) -> Self
Available on crate feature logfmt only.
pub fn stderr_logfmt(self) -> Self
logfmt only.Install a stderr sink with the logfmt format.
Source§impl LoggerBuilder
impl LoggerBuilder
Sourcepub fn stdout_human(self) -> Self
Available on crate feature human only.
pub fn stdout_human(self) -> Self
human only.Install a stdout sink with the human-readable format.
Sourcepub fn stderr_human(self) -> Self
Available on crate feature human only.
pub fn stderr_human(self) -> Self
human only.Install a stderr sink with the human-readable format.