1use chrono::Local;
2use colored::Colorize;
3
4#[derive(Debug)]
5pub struct Logger {
6 name: String,
7}
8
9impl Logger {
10 pub fn new(name: &str) -> Self {
11 Logger {
12 name: name.to_string(),
13 }
14 }
15
16 pub fn set_name(&mut self, new_name: &str) {
17 self.name = new_name.to_string();
18 }
19
20 pub fn warn(&self, message: &str) {
21 println!(
22 "{} {} ({}) {}",
23 Local::now().format("%r %D").to_string().bright_black(),
24 "WARN ".bright_yellow(),
25 self.name.bright_white(),
26 message.bright_yellow()
27 )
28 }
29
30 pub fn info(&self, message: &str) {
31 println!(
32 "{} {} ({}) {}",
33 Local::now().format("%r %D").to_string().bright_black(),
34 "INFO ".bright_cyan(),
35 self.name.bright_white(),
36 message.bright_cyan()
37 )
38 }
39
40 pub fn error(&self, message: &str) {
41 println!(
42 "{} {} ({}) {}",
43 Local::now().format("%r %D").to_string().bright_black(),
44 "ERROR".bright_red(),
45 self.name.bright_white(),
46 message.bright_red()
47 )
48 }
49
50 pub fn debug(&self, message: &str) {
51 println!(
52 "{} {} ({}) {}",
53 Local::now().format("%r %D").to_string().bright_black(),
54 "DEBUG".bright_green(),
55 self.name.bright_white(),
56 message.bright_green(),
57 )
58 }
59}