LoggerBuilder

Struct LoggerBuilder 

Source
pub struct LoggerBuilder { /* private fields */ }
Expand description

Builder for a well configured Logger

This struct helps configure a global logger that can be used with either macros or methods, see Logger.

§Examples

Logger::builder()
    .uptime(true)
    .build();
info!("hello world");

Implementations§

Source§

impl LoggerBuilder

Source

pub fn build(self) -> Result<Logger>

use the configured settings to build and initialize a new global Logger

This will build a functional Logger. You don’t need to use the Logger struct, it’s better to use the macros:

  • error!
  • warn!
  • info!
  • debug!
  • trace!

instead of the methods of the Logger struct. You can however use the Logger struct in cases where usage of a macro is bad or you are somehow working with multiple loggers.

§Examples
Logger::builder()
    .uptime(true)
    .build();
info!("hello world");
§Errors

This function will return an error if a global Logger was aready initialized. This module uses the tracing crate for logging, so if a tracing logger is initialized elsewhere, this method will error.

Source

pub const fn log_to_file(self, log_to_file: bool) -> Self

enable or disable logging to and creating of logfiles

If you want to log to a file, don’t forget to set Self::log_dir!

Default: false

Source

pub fn log_dir(self, log_dir: PathBuf) -> Self

set a directory where logfiles would be created in

Enable or disable creation and logging to logfiles with log_to_file.

Default: DEFAULT_LOG_DIR (/dev/null)

Source

pub const fn ansi(self, ansi: bool) -> Self

enable or disable ANSI control sequences

Disabling ANSI control sequences might improve compatibility and readability when the logs are displayed by a program that does not interpret them.

Keeping ANSI control sequences enabled has the disadvantage of added colors for the logs.

Default: true

Source

pub const fn display_filename(self, display_filename: bool) -> Self

when making a log, display the source file in which a log was crated in

Default: false

Source

pub const fn display_time(self, show_time: bool) -> Self

when making a log, display the time of the message

Default: true

Source

pub const fn display_level(self, display_level: bool) -> Self

when making a log, display the log level of the message

Default: true

Source

pub const fn display_target(self, display_target: bool) -> Self

show target context

Default: false

Source

pub const fn display_thread_ids(self, display_thread_ids: bool) -> Self

show the id of the thread that created this message

Default: false

Source

pub const fn display_thread_names(self, display_thread_names: bool) -> Self

show the name of the thread that created this message

Default: false

Source

pub const fn display_line_number(self, display_line_number: bool) -> Self

show which line in the source file produces a log

Default: false

Source

pub const fn pretty(self, pretty: bool) -> Self

splits a log over multiple lines, looks like a python traceback

Default: false

Source

pub const fn uptime(self, uptime: bool) -> Self

show timestamps as uptime (duration since the logger was initialized)

Default: false

Source

pub const fn set_level(self, max_level: Level) -> Self

set the lowest loglevel to be displayed

Default: Level::INFO

Source

pub const fn span_events(self, span_events: FmtSpan) -> Self

set how span events are handled

Default: FmtSpan::NONE

Trait Implementations§

Source§

impl Debug for LoggerBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LoggerBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Ord for LoggerBuilder

Source§

fn cmp(&self, other: &LoggerBuilder) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for LoggerBuilder

Source§

fn eq(&self, other: &LoggerBuilder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for LoggerBuilder

Source§

fn partial_cmp(&self, other: &LoggerBuilder) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for LoggerBuilder

Source§

impl StructuralPartialEq for LoggerBuilder

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more