Skip to main content

LogBuilder

Struct LogBuilder 

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

Struct for building a new logger

Implementations§

Source§

impl LogBuilder

Source

pub fn new() -> Self

Creates a new instance of the LogBuilder

§Defaults
  • level -> The default level is Info
  • exclude -> No targets are excluded
  • time_format -> dd.mm.YY HH:MM:SS
  • log_target -> false
§Example
//! Example for initializing the logger with the LogBuilder
use log::{error, warn, info, debug, trace};
use loggify::LogBuilder;
 
/// The `LogBuilder` is used to set more logger options
/// This example will change the log level to Trace
/// and the printed time format to time only
fn main() {
    LogBuilder::new()
        .set_level(log::Level::Trace)
        .set_time_format(String::from("%H:%M:%S"))
        .build()
        .unwrap();
 
    error!("My error message");
    warn!("My warn message");
    info!("My info message");
    debug!("My debug message");
    trace!("My trace message");
}
Source

pub fn add_exclude(self, name: String) -> Self

Adds a new target to exclude from logging

See the example exclude for usage

Source

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

Sets the minimum level

Source

pub fn set_time_format(self, format: String) -> Self

Sets the time format See https://docs.rs/chrono/0.4.6/chrono/format/strftime/index.html for supported escape sequences

Source

pub fn set_log_target(self, state: bool) -> Self

Defines if the log target should be printed or not This option should be used to find out where a log comes from and what target to exclude from logging

Source

pub fn disable_color(self) -> Self

Disables color output Per default true

Source

pub fn build(self) -> Result<(), SetLoggerError>

Creates a new logger

Trait Implementations§

Source§

impl Default for LogBuilder

Source§

fn default() -> Self

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

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.