Struct LoggerBuilder

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

Used by Logger to provide more flexibility in the configuration of the final logger.

Implementations§

Source§

impl LoggerBuilder

Source

pub fn add_console_handler(self) -> Self

Adds a ConsoleHandler with the default formatter.

§Examples
extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_console_handler()
    .build();
Source

pub fn add_console_handler_with( self, format_type: FormatType, custom_formatter: Option<Box<dyn FormatTrait>>, ) -> Self

Adds a ConsoleHandler with the required formatter.

§Parameters
  • format_type - The format type used to produce the required formatter.
  • custom_formatter - The optional boxed custom formatter. Used by the FormatType::Custom to produce a Formatter::Custom.
§Examples

First, using a provided formatter:

extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_console_handler_with(FormatType::Iso8601, None)
    .build();

Now using a custom formatter:

extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_console_handler_with(
        FormatType::Custom("MockFormatter".to_string()),
        Some(Box::new(MockFormatter::new())),
    )
    .build();
Source

pub fn add_custom_handler( self, label: &str, custom_handler: Box<dyn HandlerTrait>, ) -> Self

Adds a custom handler with the default formatter.

§Parameters
  • label - Unique identifier for this custom handler. Used when attempting to retrieve this handler: has_handler(), get_handler()
  • custom_handler - The boxed custom handler.
§Examples
extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_custom_handler(
        "MockHandler",
        Box::new(MockHandler::create("What ever you need").unwrap()),
    )
    .build();
Source

pub fn add_custom_handler_with( self, label: &str, custom_handler: Box<dyn HandlerTrait>, format_type: FormatType, custom_formatter: Option<Box<dyn FormatTrait>>, ) -> Self

Adds a custom handler with the required formatter.

§Parameters
  • label - Unique identifier for this custom handler. Used when attempting to retrieve this handler: has_handler(), get_handler()
  • custom_handler - The boxed custom handler.
  • format_type - The format type used to produce the required formatter.
  • custom_formatter - The optional boxed custom formatter. Used by the FormatType::Custom to produce a Formatter::Custom.
§Examples

First, using a provided formatter:

extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_custom_handler_with(
        "MockHandler",
        Box::new(MockHandler::create("What ever you need").unwrap()),
        FormatType::Simple,
        None,
    )
    .build();

Now using a custom formatter:

extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_custom_handler_with(
        "MockHandler",
        Box::new(MockHandler::create("What ever you need").unwrap()),
        FormatType::Custom("MockFormatter".to_string()),
        Some(Box::new(MockFormatter::new())),
    )
    .build();
Source

pub fn add_file_handler(self, filename: &str) -> Self

Adds a FileHandler with the default formatter.

§Parameters
  • filename - The name of the output log file. Must include any relevant path (relative or absolute).
§Examples
extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_file_handler("mylog.txt")
    .build();
Source

pub fn add_file_handler_with( self, filename: &str, format_type: FormatType, custom_formatter: Option<Box<dyn FormatTrait>>, ) -> Self

Adds a FileHandler with the required formatter.

§Parameters
  • filename - The name of the output log file. Must include any relevant path (relative or absolute).
  • format_type - The format type used to produce the required formatter.
  • custom_formatter - The optional boxed custom formatter. Used by the FormatType::Custom to produce a Formatter::Custom.
§Examples

First, using a provided formatter:

extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_file_handler_with("mylog.txt", FormatType::Iso8601, None)
    .build();

Now using a custom formatter:

extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_file_handler_with(
        "mylog.txt",
        FormatType::Custom("MockFormatter".to_string()),
        Some(Box::new(MockFormatter::new())),
    )
    .build();
Source

pub fn add_string_handler(self) -> Self

Adds a StringHandler with the default formatter.

§Examples
extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_string_handler()
    .build();
Source

pub fn add_string_handler_with( self, format_type: FormatType, custom_formatter: Option<Box<dyn FormatTrait>>, ) -> Self

Adds a StringHandler with the required formatter.

§Parameters
  • format_type - The format type used to produce the required formatter.
  • custom_formatter - The optional boxed custom formatter. Used by the FormatType::Custom to produce a Formatter::Custom.
§Examples

First, using a provided formatter:

extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_string_handler_with(FormatType::Iso8601, None)
    .build();

Now using a custom formatter:

extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_string_handler_with(
        FormatType::Custom("MockFormatter".to_string()),
        Some(Box::new(MockFormatter::new())),
    )
    .build();
Source

pub fn build(self) -> Logger

Complete the build process and produce the final Logger instance.

§Examples
extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_console_handler()
    .build();
Source

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

Set the logging level for the Logger instance being configured.

§Parameters
  • level - The new level to set.
§Examples
extern crate flogging;
use flogging::*;

let mut log = Logger::builder(module_path!())
    .add_console_handler()
    .set_level(Level::ALL)
    .build();

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.