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
impl LoggerBuilder
Sourcepub fn add_console_handler(self) -> Self
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();Sourcepub fn add_console_handler_with(
self,
format_type: FormatType,
custom_formatter: Option<Box<dyn FormatTrait>>,
) -> Self
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 theFormatType::Customto produce aFormatter::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();Sourcepub fn add_custom_handler(
self,
label: &str,
custom_handler: Box<dyn HandlerTrait>,
) -> Self
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();Sourcepub fn add_custom_handler_with(
self,
label: &str,
custom_handler: Box<dyn HandlerTrait>,
format_type: FormatType,
custom_formatter: Option<Box<dyn FormatTrait>>,
) -> Self
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 theFormatType::Customto produce aFormatter::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();Sourcepub fn add_file_handler(self, filename: &str) -> Self
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();Sourcepub fn add_file_handler_with(
self,
filename: &str,
format_type: FormatType,
custom_formatter: Option<Box<dyn FormatTrait>>,
) -> Self
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 theFormatType::Customto produce aFormatter::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();Sourcepub fn add_string_handler(self) -> Self
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();Sourcepub fn add_string_handler_with(
self,
format_type: FormatType,
custom_formatter: Option<Box<dyn FormatTrait>>,
) -> Self
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 theFormatType::Customto produce aFormatter::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();Auto Trait Implementations§
impl !Freeze for LoggerBuilder
impl !RefUnwindSafe for LoggerBuilder
impl Send for LoggerBuilder
impl !Sync for LoggerBuilder
impl Unpin for LoggerBuilder
impl !UnwindSafe for LoggerBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more