init_stdout_logger

Function init_stdout_logger 

Source
pub fn init_stdout_logger(config: LoggerConfig) -> Result<(), LogError>
Expand description

Initialize a logger that only writes to stdout (not to a file).

§Arguments

  • config - Configuration options for the logger.

§Returns

Ok(()) if initialization succeeded, or an error if it failed.

§Example

use fstdout_logger::{init_stdout_logger, LoggerConfig};

init_stdout_logger(LoggerConfig::default())
    .expect("Failed to initialize stdout logger");
Examples found in repository?
examples/stdout_only.rs (line 21)
13fn main() {
14    // Initialize logger with stdout only (no file output) with colors
15    let config = LoggerConfig::builder()
16        .level(LevelFilter::Debug) // Show Debug level and above
17        .show_file_info(false) // Don't show file and line information
18        .use_colors(true) // Use colors in output
19        .build();
20
21    if let Err(e) = init_stdout_logger(config) {
22        eprintln!("Failed to initialize logger: {e}");
23        return;
24    }
25
26    println!("Logger initialized! Output will only appear on stdout.");
27    println!("Notice that TRACE level messages won't show because we set Debug as minimum level.");
28    println!("Also note that file and line information is hidden for cleaner output.");
29
30    // Log messages at different levels to demonstrate filtering
31    trace!("This is a TRACE message - you won't see this");
32    debug!("This is a DEBUG message - visible");
33    info!("This is an INFO message - visible");
34    warn!("This is a WARNING message - visible");
35    error!("This is an ERROR message - visible");
36
37    // Log messages with dynamic content
38    for i in 1..=3 {
39        let value = i * 10;
40        debug!("Debug calculation: {i} * 10 = {value}");
41        info!("Processing item #{i} with value {value}");
42    }
43
44    info!("Example completed");
45}