1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use colored::Colorize;
use log::{Level, LevelFilter, Metadata, Record};

pub struct MinimalLogger;

impl log::Log for MinimalLogger {
    fn enabled(&self, _metadata: &Metadata) -> bool {
        true
    }

    fn log(&self, record: &Record) {
        // Filter out INFO messages from commitlog
        if record.level() == Level::Info && record.target().starts_with("commitlog") {
            return;
        }

        // Inspired by https://github.com/borntyping/rust-simple_logger/blob/ce8ec4bbe5f81cfd2f7a852f68e308369ef7fa5f/src/lib.rs#L199-L203
        let level_string = match record.level() {
            Level::Error => record.level().to_string().red(),
            Level::Warn => record.level().to_string().yellow(),
            Level::Info => record.level().to_string().cyan(),
            Level::Debug => record.level().to_string().purple(),
            Level::Trace => record.level().to_string().normal(),
        };

        if record.level() > LevelFilter::Error {
            println!("{level_string:<5} {}", record.args());
        } else {
            eprintln!("{level_string:<5} {}", record.args());
        }
    }

    fn flush(&self) {}
}