//! Console logger

use log::*;

/// Logs to console
pub struct CLILogger;

impl CLILogger {
    pub fn init<'a>(level: &'a str) -> Result<(), SetLoggerError> {
        set_logger(|max_log_level| {
            max_log_level.set(match level {
                "info" => LogLevelFilter::Info,
                "debug" => LogLevelFilter::Debug,
                "error" => LogLevelFilter::Error,
                "warn" => LogLevelFilter::Warn,
                "trace" => LogLevelFilter::Trace,
                _ => LogLevelFilter::Info
            });
            Box::new(CLILogger)
        })
    }
}

impl Log for CLILogger {
    fn enabled(&self, metadata: &LogMetadata) -> bool {
        metadata.level() <= max_log_level()
    }

    fn log(&self, record: &LogRecord) {
        if self.enabled(record.metadata()) {
            if record.level() == LogLevel::Info {
                println!("{}", record.args());
            } else {
                println!("[{}] - {}", record.level(), record.args());
            }
        }
    }
}

//! Console logger

use log::*;

/// Logs to console
pub struct CLILogger;

impl CLILogger {
    pub fn init<'a>(level: &'a str) -> Result<(), SetLoggerError> {
        set_logger(|max_log_level| {
            max_log_level.set(match level {
                "info" => LogLevelFilter::Info,
                "debug" => LogLevelFilter::Debug,
                "error" => LogLevelFilter::Error,
                "warn" => LogLevelFilter::Warn,
                "trace" => LogLevelFilter::Trace,
                _ => LogLevelFilter::Info
            });
            Box::new(CLILogger)
        })
    }
}

impl Log for CLILogger {
    fn enabled(&self, metadata: &LogMetadata) -> bool {
        metadata.level() <= max_log_level()
    }

    fn log(&self, record: &LogRecord) {
        if self.enabled(record.metadata()) {
            println!("[{}] - {}", record.level(), record.args());
        }
    }
}

Print log level for info messages
Print log level for info messages

Signed-off-by: Kaustav Das Modak <ba1ce5b1e09413a89404909d8d270942c5dadd14@yahoo.co.in>
