.
//
//!
//! # LoggerBuilder
//!
use crate::*;
use ::{::, ::,};
///
/// Used by [`Logger`] to provide more flexibility in the configuration of the
/// final logger.
///
pub struct LoggerBuilder {
mod_path:
fn_name:
level:
handlers: <<<>>>
}
impl LoggerBuilder {
pub(super) fn create(mod_path:) -> Self {
{
,
: String::(),
: ::(),
: ::(::()),
}
}
///
/// Adds a [`ConsoleHandler`] with the default formatter,
/// with output according to: [`ConsoleType::StdOut`].
///
/// ## Examples
/// ```
/// extern crate flogging;
/// use flogging::*;
///
/// let mut log = Logger::builder(module_path!())
/// .add_console_handler()
/// .build();
/// ```
///
pub fn add_console_handler(self) -> Self {
selfadd_handler_with(::, None, None, None, None)
}
///
/// Adds a [`ConsoleHandler`] with the required formatter,
/// with output according to: [`ConsoleType::StdOut`].
///
/// ## 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,
/// Some(Box::new(MockFormatter::new())),
/// )
/// .build();
/// ```
///
pub fn add_console_handler_with(
self
format_type:
custom_formatter: <<>>
) -> Self {
selfadd_handler_with(
::,
None,
None,
Some(),
,
)
}
///
/// Adds a [`ConsoleHandler`] with the default formatter,
/// with output according to: [`ConsoleType::StdErr`].
///
/// ## Examples
/// ```
/// extern crate flogging;
/// use flogging::*;
///
/// let mut log = Logger::builder(module_path!())
/// .add_econsole_handler()
/// .build();
/// ```
///
pub fn add_econsole_handler(self) -> Self {
selfadd_handler_with(::, None, None, None, None)
}
///
/// Adds a [`ConsoleHandler`] with the required formatter,
/// with output according to: [`ConsoleType::StdErr`].
///
/// ## 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_econsole_handler_with(FormatType::Iso8601, None)
/// .build();
/// ```
/// Now using a custom formatter:
/// ```
/// extern crate flogging;
/// use flogging::*;
///
/// let mut log = Logger::builder(module_path!())
/// .add_econsole_handler_with(
/// FormatType::Custom,
/// Some(Box::new(MockFormatter::new())),
/// )
/// .build();
/// ```
///
pub fn add_econsole_handler_with(
self
format_type:
custom_formatter: <<>>
) -> Self {
selfadd_handler_with(
::,
None,
None,
Some(),
,
)
}
///
/// 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()`][Logger::has_handler], [`get_handler()`][Logger::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();
/// ```
///
pub fn add_custom_handler(selflabel: &strcustom_handler: <>) -> Self {
selfadd_handler_with(
::(to_string()),
Some(),
None,
None,
None,
)
}
///
/// 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()`][Logger::has_handler], [`get_handler()`][Logger::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,
/// Some(Box::new(MockFormatter::new())),
/// )
/// .build();
/// ```
///
pub fn add_custom_handler_with(
self
label: &str
custom_handler: <>
format_type:
custom_formatter: <<>>
) -> Self {
selfadd_handler_with(
::(to_string()),
Some(),
None,
Some(),
,
)
}
///
/// 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("test_logs/builder.log")
/// .build();
/// ```
///
pub fn add_file_handler(selffilename: &str) -> Self {
selfadd_handler_with(::, None, Some(), None, None)
}
///
/// 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("test_logs/builder.log", 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(
/// "test_logs/builder.log",
/// FormatType::Custom,
/// Some(Box::new(MockFormatter::new())),
/// )
/// .build();
/// ```
///
pub fn add_file_handler_with(
self
filename: &str
format_type:
custom_formatter: <<>>
) -> Self {
selfadd_handler_with(
::,
None,
Some(),
Some(),
,
)
}
fn add_handler_with(
mut self
handler:
custom_handler: <<>>
filename: <&str>
format_type: <>
custom_formatter: <<>>
) -> Self {
let=unwrap_or(&self);
let mut: <> = match{
::=> {
Box::(::(::as_str())unwrap())
}
::=> {
Box::(::(::as_str())unwrap())
}
::=> Box::(::()unwrap()),
::=> {
Box::(::(::as_str())unwrap())
}
::=> Box::(::()unwrap()),
::(_) =>unwrap(),
};
if let Some() ={
set_formatter(match{
::=>create(None),
::=>create(None),
::=>create(None),
::=>create(),
});
}
let= selfget_mut();
insert(,);
self
}
///
/// Adds a [`ConsoleHandler`] with the default formatter,
/// with output according to: [`ConsoleType::Production`].
///
/// ## Examples
/// ```
/// extern crate flogging;
/// use flogging::*;
///
/// let mut log = Logger::builder(module_path!())
/// .add_pconsole_handler()
/// .build();
/// ```
///
pub fn add_pconsole_handler(self) -> Self {
selfadd_handler_with(::, None, None, None, None)
}
///
/// Adds a [`ConsoleHandler`] with the required formatter,
/// with output according to: [`ConsoleType::Production`].
///
/// ## 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_pconsole_handler_with(FormatType::Iso8601, None)
/// .build();
/// ```
/// Now using a custom formatter:
/// ```
/// extern crate flogging;
/// use flogging::*;
///
/// let mut log = Logger::builder(module_path!())
/// .add_pconsole_handler_with(
/// FormatType::Custom,
/// Some(Box::new(MockFormatter::new())),
/// )
/// .build();
/// ```
///
pub fn add_pconsole_handler_with(
self
format_type:
custom_formatter: <<>>
) -> Self {
selfadd_handler_with(
::,
None,
None,
Some(),
,
)
}
///
/// Adds a [`StringHandler`] with the default formatter.
///
/// ## Examples
/// ```
/// extern crate flogging;
/// use flogging::*;
///
/// let mut log = Logger::builder(module_path!())
/// .add_string_handler()
/// .build();
/// ```
///
pub fn add_string_handler(self) -> Self {
selfadd_handler_with(::, None, None, None, None)
}
///
/// 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,
/// Some(Box::new(MockFormatter::new())),
/// )
/// .build();
/// ```
///
pub fn add_string_handler_with(
self
format_type:
custom_formatter: <<>>
) -> Self {
selfadd_handler_with(
::,
None,
None,
Some(),
,
)
}
///
/// 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();
/// ```
///
pub fn build(self) -> {
{
: selfclone(),
: selfclone(),
: self,
: self,
}
}
///
/// Remove an existing log file.
///
/// The purpose of this, is to allow resetting of the log file, each time
/// a test run is done.
///
/// ## Note
///
/// This **must** be called _before_ adding the corresponding file handler
/// that is going to open this file.
///
/// ## 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!())
/// .remove_file("test_logs/builder.log")
/// .add_file_handler("test_logs/builder.log")
/// .build();
/// ```
///
pub fn remove_file(selffilename: &str) -> Self {
let _ = ::()is_err();
self
}
///
/// Set the current function/method name.
///
/// ## Parameters
/// - `fn_name` - The name of the function/method in which you are
/// logging.
///
/// Returns itself for chaining purposes.
///
pub fn set_fn_name(mut selffn_name: &str) -> Self {
self=to_string();
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();
/// ```
///
pub fn set_level(mut selflevel:) -> Self {
self=;
self
}
}
#[cfg()]
mod tests {
use crate::*;
use ::;
use ::::{Result,,,};
#[test]
fn temp() -> <()> {
let= "arguments";
let mut= stdout();
writeln!(
"test")?;
writeln!( "formatted {}",)?;
// assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes());
Ok(())
}
#[test]
fn add_console_handler() {
let= "flogging::logger::builder::tests->add_console_handler [INFO ] We begin!
flogging::logger::builder::tests->add_console_handler [WARNING] Need more tests.
"
to_string();
let mut= ::(module_path!())
add_console_handler()
set_fn_name("add_console_handler")
build();
let=get_handler(crate::::)unwrap();
set_test_mode(true);
info("We begin!");
warning("Need more tests.");
let=get_handler(crate::::)unwrap();
let=get_log();
assert_eq!(,);
}
#[test]
fn add_console_handler_with() {
let=
"^(?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{9}\\+\\d{2}:\\d{2}) flogging::logger::builder::tests->add_console_handler_with \\[INFO ] We begin!
(?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{9}\\+\\d{2}:\\d{2}) flogging::logger::builder::tests->add_console_handler_with \\[WARNING] Need more tests.
$";
let= ::()unwrap();
let mut= ::(module_path!())
add_console_handler_with(::, None)
set_fn_name("add_console_handler_with")
build();
let=get_handler(crate::::)unwrap();
set_test_mode(true);
info("We begin!");
warning("Need more tests.");
let=get_handler(crate::::)unwrap();
let=get_log();
println!("{result}");
assert!(is_match(&));
}
#[test]
fn add_econsole_handler() {
let mut= ::(module_path!())
add_econsole_handler()
set_fn_name("add_econsole_handler")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn add_econsole_handler_with() {
let mut= ::(module_path!())
add_econsole_handler_with(::, None)
set_fn_name("add_econsole_handler_with")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn add_custom_handler() {
let mut= ::(module_path!())
add_custom_handler(
"Console",
Box::(::(::as_str())unwrap()),
)
set_fn_name("add_custom_handler")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn add_custom_handler_with() {
let mut= ::(module_path!())
add_custom_handler_with(
"Console",
Box::(::(::as_str())unwrap()),
::,
Some(Box::(::())),
)
set_fn_name("add_custom_handler_with")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn add_file_handler() {
let mut= ::(module_path!())
add_file_handler("test_logs/add_file_handler.log")
set_fn_name("add_file_handler")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn add_file_handler_with() {
let mut= ::(module_path!())
add_file_handler_with(
"test_logs/add_file_handler_with.log",
crate::::,
None,
)
set_fn_name("add_file_handler_with")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn add_pconsole_handler() {
let mut= ::(module_path!())
add_pconsole_handler()
set_fn_name("add_pconsole_handler")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn add_pconsole_handler_with() {
let mut= ::(module_path!())
add_pconsole_handler_with(::, None)
set_fn_name("add_pconsole_handler_with")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn add_string_handler() {
let mut= ::(module_path!())
add_string_handler()
set_fn_name("add_string_handler")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn add_string_handler_with() {
let mut= ::(module_path!())
add_string_handler_with(crate::::, None)
set_fn_name("add_string_handler_with")
build();
info("We begin!");
warning("Need more tests.");
}
#[test]
fn remove_file() {
let mut= ::(module_path!())
remove_file("test_logs/remove_file.log")
add_file_handler("test_logs/remove_file.log")
set_fn_name("add_file_handler")
build();
info("We begin!");
warning("Need more tests.");
}
}