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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use colored::Colorize;


// Custom logger that contains a title on every message
// I recommend to initialize it as a global variable using lazy_static!
// Example:
// lazy_static! {
//     pub static ref log: Logger = Logger::new("MyApp");
// }
//
// Then you can use it like this:
// log.info("Hello World!");
// log.warn("Something is wrong!");
// log.error("Something is very wrong!");
// log.error_exit("Something is very wrong and I can't continue!");
pub struct Logger {
    title: String,
}

impl Logger {
    pub fn new(title: &str) -> Logger {
        Logger {
            title: title.to_string(),
        }
    }

    pub fn info(&self, message: &str) {
        println!("{} {}", self.title, message.blue());
    }

    pub fn warn(&self, message: &str) {
        println!("{} {}", self.title, message.yellow());
    }
    
    pub fn error(&self, message: &str) {
        println!("{} {}", self.title, message.red().bold());
    }
    
    pub fn error_exit(&self, message: &str) -> ! {
        println!("{} {}", self.title, message.red().bold());
        std::process::exit(1);
    }
}


pub fn info(message: &str) {
    println!("{}", message.blue());
}

pub fn warn(message: &str) {
    println!("{}", message.yellow());
}

pub fn error(message: &str) {
    println!("{}", message.red().bold());
}

pub fn error_exit(message: &str) -> ! {
    println!("{}", message.red().bold());
    std::process::exit(1);
}