// examples/global.rs
// Demonstrates the global logger + macros (info!, try_info!, etc).
// Run: cargo run --example global

use log_easy::{
    LogLevel, Logger, debug, error, info, trace, try_debug, try_error, try_info, try_trace,
    try_warn, warn,
};
use std::io::Result;

fn main() -> Result<()> {
    // Initialize the global logger with a file path and log level.
    log_easy::init_with(Logger::new("target/global.log").with_level(LogLevel::Trace))?;

    // Non-fallible macros (errors are printed to stderr).
    trace!("This is a trace message");
    debug!("Debugging information here");
    info!("Application started");
    warn!("This is a warning");
    error!("An error occurred");

    // Fallible macros (return Result so you can handle failures).
    try_trace!("This is a trace message using the try macro")?;
    try_debug!("This is a debug message using the try macro")?;
    try_info!("This is an info message using the try macro")?;
    try_warn!("This is a warning message using the try macro")?;
    try_error!("This is an error message using the try macro")?;

    // Macros accept formatting args.
    let user = "joe";
    let attempts = 3;
    let elapsed_ms = 127;
    info!("User {user} has attempted login {attempts} times ({elapsed_ms}ms elapsed)");

    Ok(())
}
