Skip to main content

LoggerBuilder

Struct LoggerBuilder 

Source
pub struct LoggerBuilder { /* private fields */ }
Available on crate feature 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

Source

pub fn level(self, level: Level) -> Self

Set the default minimum severity.

Source

pub fn filter(self, filter: Filter) -> Self

Replace the filter wholesale.

Source

pub fn target_level(self, target: impl Into<String>, level: Level) -> Self

Add a per-target filter override. See Filter::with_rule.

Source

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.

Source

pub fn no_timestamps(self) -> Self

Disable timestamp capture. By default the logger records a timestamp on every record using std::time::SystemTime.

Source

pub fn no_context(self) -> Self

Disable thread-local context capture.

Source

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.

Source

pub fn on_error(self, handler: Arc<dyn Fn(&Error) + Send + Sync>) -> Self

Install a callback invoked when a sink returns an error.

Source

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).

Source

pub fn stdout<F>(self, format: F) -> Self
where F: Format + Send + Sync + 'static,

Install a stdout sink with the given format.

Source

pub fn stderr<F>(self, format: F) -> Self
where F: Format + Send + Sync + 'static,

Install a stderr sink with the given format.

Source

pub fn writer<W, F>(self, writer: W, format: F) -> Self
where W: Write + Send + 'static, F: Format + Send + Sync + 'static,

Install a sink that writes to writer with format.

Source

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

Source

pub fn stdout_json(self) -> Self

Available on crate feature json only.

Install a stdout sink with the default JSON format.

Source

pub fn stderr_json(self) -> Self

Available on crate feature json only.

Install a stderr sink with the default JSON format.

Source§

impl LoggerBuilder

Source

pub fn stdout_logfmt(self) -> Self

Available on crate feature logfmt only.

Install a stdout sink with the logfmt format.

Source

pub fn stderr_logfmt(self) -> Self

Available on crate feature logfmt only.

Install a stderr sink with the logfmt format.

Source§

impl LoggerBuilder

Source

pub fn stdout_human(self) -> Self

Available on crate feature human only.

Install a stdout sink with the human-readable format.

Source

pub fn stderr_human(self) -> Self

Available on crate feature human only.

Install a stderr sink with the human-readable format.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.