Skip to main content

init_with

Function init_with 

Source
pub fn init_with(logger: Logger) -> Result<()>
Expand description

Initialize the global logger with configured settings (e.g., log level). Useful if you want to set a different log level for the global logger.

ยงErrors

Returns AlreadyExists if the global logger has already been initialized.

Examples found in repository?
examples/global.rs (line 13)
11fn main() -> Result<()> {
12    // Initialize the global logger with a file path and log level.
13    log_easy::init_with(Logger::new("target/global.log").with_level(LogLevel::Trace))?;
14
15    // Non-fallible macros (errors are printed to stderr).
16    trace!("This is a trace message");
17    debug!("Debugging information here");
18    info!("Application started");
19    warn!("This is a warning");
20    error!("An error occurred");
21
22    // Fallible macros (return Result so you can handle failures).
23    try_trace!("This is a trace message using the try macro")?;
24    try_debug!("This is a debug message using the try macro")?;
25    try_info!("This is an info message using the try macro")?;
26    try_warn!("This is a warning message using the try macro")?;
27    try_error!("This is an error message using the try macro")?;
28
29    // Macros accept formatting args.
30    let user = "joe";
31    let attempts = 3;
32    let elapsed_ms = 127;
33    info!("User {user} has attempted login {attempts} times ({elapsed_ms}ms elapsed)");
34
35    Ok(())
36}