1use chrono::Local;
2use colored::*;
3
4pub struct Logger {
5 website: String,
6}
7
8impl Logger {
9 pub fn new(website: &str) -> Self {
10 Logger {
11 website: website.to_string(),
12 }
13 }
14
15 fn current_time() -> String {
16 let now = Local::now();
17 now.format("%H:%M:%S.%3f").to_string()
18 }
19
20 pub fn log(&self, msg: &str) {
21 let time = Self::current_time();
22 println!(
23 "{} | [{}] : {}",
24 time.white(),
25 self.website.cyan(),
26 msg.white()
27 );
28 }
29
30 pub fn blue(&self, msg: &str) {
31 let time = Self::current_time();
32 println!(
33 "{} | [{}] : {}",
34 time.white(),
35 self.website.blue(),
36 msg.blue()
37 );
38 }
39
40 pub fn red(&self, msg: &str) {
41 let time = Self::current_time();
42 println!(
43 "{} | [{}] : {}",
44 time.white(),
45 self.website.red(),
46 msg.red()
47 );
48 }
49
50 pub fn green(&self, msg: &str) {
51 let time = Self::current_time();
52 println!(
53 "{} | [{}] : {}",
54 time.white(),
55 self.website.green(),
56 msg.green()
57 );
58 }
59
60 pub fn yellow(&self, msg: &str) {
61 let time = Self::current_time();
62 println!(
63 "{} | [{}] : {}",
64 time.white(),
65 self.website.yellow(),
66 msg.yellow()
67 );
68 }
69
70 pub fn error(&self, msg: &str) {
71 let time = Self::current_time();
72 eprintln!(
73 "{} | [{}] : {}",
74 time.white(),
75 self.website.red(),
76 msg.red().bold()
77 );
78 }
79}