Function set_max_level

Source
pub fn set_max_level(level: Level)
Expand description

Sets the global maximum log level.

Only log messages with a severity level equal to or numerically lower than this value will be displayed (e.g., if Level::Info is set, Info, Warn, and Error messages will be shown).

§Arguments

  • level - The maximum Level to log.

§Examples

use dev_utils::dlog::{set_max_level, Level};
set_max_level(Level::Warn); // Only Warn and Error messages will be shown.
Examples found in repository?
examples/some_tester.rs (line 14)
10fn main() {
11    app_dt!(file!());
12    // app_dt!(file!(), "package" => ["license", "keywords"]);
13
14    set_max_level(dev_utils::dlog::Level::Trace);
15
16    // test_io();
17    // test_pause();
18    // f();
19    some();
20}
More examples
Hide additional examples
examples/main_tester.rs (line 10)
3fn main() {
4    // 1. Display application information from Cargo.toml
5    app_dt!(file!()); // This macro clears the screen and prints.
6
7    app_dt!(file!(), "package" => ["license", "description"]); // Or select specific fields:
8
9    // 2. Use the enhanced logger
10    dev_utils::dlog::set_max_level(dev_utils::dlog::Level::Trace); // Set desired log level
11    info!("Application started successfully!");
12}
examples/dlog.rs (line 12)
3fn main() {
4    app_dt!(file!());
5
6    println!(
7        "{}",
8        "--- dlog Showcase ---".style(Style::Bold).color(CYAN)
9    );
10
11    // Initialize logging
12    set_max_level(Level::Trace);
13
14    // showcase_log_levels();
15    // showcase_log_use_cases(); // * gen some delay's to simulate real-world scenarios
16    // showcase_log_formatting();
17    // showcase_datetime_features(); // Not very awesome... .__.
18    showcase_log_performance();  // = 352.6482ms / 10000 logs (average of 10 runs)
19}
20
21fn showcase_log_levels() {
22    println!(
23        "\n{}",
24        "Log Levels Demonstration:"
25            .style(Style::Bold)
26            .style(Style::Italic)
27    );
28
29    // Helper function to set log level, print color-coded messages, and log all levels
30    fn demonstrate_log_level(level: Level, color: Color, description: &str) {
31        println!(
32            "\n{}",
33            format!("Log Level: {}", description)
34                .style(Style::Bold)
35                .color(color)
36        );
37        set_max_level(level);
38        log_all_levels();
39    }
40
41    // Function to log messages at all levels
42    fn log_all_levels() {
43        trace!("Most detailed level, useful for step-by-step debugging");
44        debug!("Useful for diagnosing issues");
45        info!("General operational messages about program execution");
46        warn!("Something unexpected happened, but the program can still continue");
47        error!("A serious problem occurred, indicating potential a failure");
48    }
49
50    // Demonstrate log levels with different settings
51    demonstrate_log_level(
52        Level::Trace,
53        Color::new(180, 0, 158),
54        "Trace (all levels visible)",
55    );
56    demonstrate_log_level(
57        Level::Debug,
58        Color::new(97, 214, 214),
59        "Debug (Trace hidden, Debug and above visible)",
60    );
61    demonstrate_log_level(
62        Level::Info,
63        Color::new(22, 198, 12),
64        "Info (Trace and Debug hidden, Info and above visible)",
65    );
66    demonstrate_log_level(
67        Level::Warn,
68        Color::new(245, 245, 57),
69        "Warn (Only Warn and Error visible)",
70    );
71    demonstrate_log_level(
72        Level::Error,
73        Color::new(231, 72, 86),
74        "Error (Only Error logs visible)",
75    );
76
77    // Restore Trace level at the end
78    set_max_level(Level::Trace);
79    println!(
80        "\n{}",
81        "Log Level restored to Trace."
82            .style(Style::Bold)
83            .color(GREEN)
84    );
85}