fstdout_logger/examples/
mod.rs

1use colored::Colorize;
2
3/// Display example log messages with colors to demonstrate the output format
4pub fn show_colored_log_examples() {
5    println!("=== COLORED LOG EXAMPLES ===");
6
7    let timestamp = chrono::Local::now().format("%H:%M:%S");
8    let colored_time = timestamp.to_string().bright_black();
9
10    println!(
11        "[{} {}] This is a TRACE message",
12        colored_time,
13        "TRACE".normal()
14    );
15
16    println!(
17        "[{} {}] This is a DEBUG message",
18        colored_time,
19        "DEBUG".green()
20    );
21
22    println!(
23        "[{} {}] This is an INFO message",
24        colored_time,
25        "INFO".blue().bold()
26    );
27
28    println!(
29        "[{} {}] This is a WARNING message",
30        colored_time,
31        "WARN".yellow().bold()
32    );
33
34    println!(
35        "[{} {}] This is an ERROR message",
36        colored_time,
37        "ERROR".red().bold()
38    );
39
40    println!(" ");
41}
42
43/// Display example log messages without colors to demonstrate the output format.
44///
45/// Shows how log messages appear in plain text without any color formatting.
46/// This is similar to how logs would appear in a terminal with colors disabled.
47pub fn show_plain_log_examples() {
48    println!("=== PLAIN TEXT LOG EXAMPLES ===");
49
50    let timestamp = chrono::Local::now().format("%H:%M:%S");
51
52    println!("[{timestamp} TRACE] This is a TRACE message");
53
54    println!("[{timestamp} DEBUG] This is a DEBUG message");
55
56    println!("[{timestamp} INFO] This is an INFO message");
57
58    println!("[{timestamp} WARN] This is a WARNING message");
59
60    println!("[{timestamp} ERROR] This is an ERROR message");
61
62    println!(" ");
63}
64
65/// Display example log messages with file information.
66///
67/// Compares how logs appear with and without file/line information.
68/// This helps visualize the difference between development logs (with file info)
69/// and production logs (without file info).
70pub fn show_file_info_examples() {
71    println!("=== LOGS WITH FILE INFO ===");
72
73    let timestamp = chrono::Local::now().format("%H:%M:%S");
74    let file = "examples/show_colors.rs";
75    let line = 42;
76
77    println!(
78        "[{} {} {}:{}] This is a log message with file info",
79        timestamp.to_string().bright_black(),
80        "INFO".blue().bold(),
81        file.bright_black(),
82        line
83    );
84
85    println!("=== LOGS WITHOUT FILE INFO ===");
86
87    println!(
88        "[{} {}] This is a log message without file info",
89        timestamp.to_string().bright_black(),
90        "INFO".blue().bold()
91    );
92
93    println!(" ");
94}