outlog 0.1.0

A simple logging system based on the log crate.
Documentation
//! Configuration.

#[cfg(feature = "config-serde")]
use serde::{Serialize, Deserialize};

/// Logging configuration.
#[derive(Clone, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "config-serde", derive(Serialize, Deserialize), serde(default))]
pub struct Config {
    /// The lowest log level that should be printed.\
    /// Set to `Off` to disable all logging.
    pub level: log::LevelFilter,

    #[cfg(feature = "color")]
    #[cfg_attr(feature = "config-serde", serde(alias = "colour"))]
    /// Whether or not to use color.\
    /// Set to `Auto` to only use color when output is a terminal.
    pub color: Color,

    #[cfg(feature = "chrono")]
    /// Format string for datetime output.\
    /// See [the chrono docs][strftime] for syntax.
    ///
    /// [strftime]: https://docs.rs/chrono/0.4.11/chrono/format/strftime/index.html
    pub datetime_format: String
}

impl Default for Config {
    /// Returns a sensible default configuration.
    #[inline]
    fn default() -> Self {
        let level = if cfg!(debug_assertions) {
            log::LevelFilter::max()
        } else {
            log::LevelFilter::Info
        };

        Self {
            level,

            #[cfg(feature = "color")]
            color: Color::Auto,

            #[cfg(feature = "chrono")]
            datetime_format: String::from("%Y-%m-%d %H:%M:%S %:z ")
        }
    }
}

#[cfg(feature = "color")]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "config-serde", derive(Serialize, Deserialize), serde(rename_all = "lowercase"))]
pub enum Color {
    Off,
    On,
    Auto
}