#[cfg(feature = "colored")]
mod colorize;
mod output;
pub use log::LevelFilter;
pub use output::Output;
#[cfg(feature = "colored")]
pub use colorize::Colorize;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Config {
#[cfg(feature = "colored")]
pub(crate) colorize: Colorize,
pub(crate) format: String,
pub(crate) level: LevelFilter,
pub(crate) modules: Vec<String>,
pub(crate) output: Vec<Output>,
}
impl Default for Config {
fn default() -> Self {
Self {
#[cfg(feature = "colored")]
colorize: Colorize::default(),
#[cfg(feature = "chrono")]
format: String::from(crate::formats::DETAIL1),
#[cfg(not(feature = "chrono"))]
format: String::from(crate::formats::SIMPLE1),
level: LevelFilter::Info,
modules: Vec::new(),
output: vec![Output::default()],
}
}
}
impl Config {
pub fn new() -> Self {
Self::default()
}
#[cfg(feature = "colored")]
pub fn colorize<T: Into<Colorize>>(mut self, colorize: T) -> Self {
self.colorize = colorize.into();
self
}
pub fn format<T: Into<String>>(mut self, format: T) -> Self {
self.format = format.into();
self
}
pub fn level<T: Into<LevelFilter>>(mut self, level: T) -> Self {
self.level = level.into();
self
}
pub fn modules<T: IntoIterator>(mut self, modules: T) -> Self
where
T::Item: Into<String>,
{
self.modules = modules.into_iter().map(|x| x.into()).collect();
self
}
pub fn module<T: Into<String>>(mut self, module: T) -> Self {
self.modules.push(module.into());
self
}
pub fn output<T: Into<Output>>(mut self, output: T) -> Self {
self.output = vec![output.into()];
self
}
pub fn add_output<T: Into<Output>>(mut self, output: T) -> Self {
self.output.push(output.into());
self
}
pub fn outputs<T: IntoIterator>(mut self, outputs: T) -> Self
where
T::Item: Into<Output>,
{
self.output = outputs.into_iter().map(|x| x.into()).collect();
self
}
}