// examples/instance.rs
// Demonstrates using a standalone Logger instance (no global macros).
// Run: cargo run --example instance

use log_easy::{LogLevel, Logger};
use std::io::Result;

fn main() -> Result<()> {
    // Parse a string into LogLevel enum.
    let level: LogLevel = "Debug".parse().expect("valid hard-coded log level");

    // Create an independent Logger instance (separate file/level) without using the global macros.
    let logger = Logger::new("target/instance.log").with_level(level);

    // Non-fallible instance logging (write failures go to stderr).
    logger.trace("This trace message will not be logged due to log level");
    logger.debug("This debug message will not be logged due to log level");
    logger.info("Instance logger ready");
    logger.warn("This is a warning with the instance logger");
    logger.error("An error occurred with the instance logger");

    // Fallible instance logging: returns Result so you can handle failures.
    logger.try_trace("This is a trace message with try")?;
    logger.try_debug("This is a debug message with try")?;
    logger.try_info("This is an info message with try")?;
    logger.try_warn("This is a warning with try")?;
    logger.try_error("An error occurred with try")?;

    // Instance loggers don't have macros, so format messages manually (macros target the global logger).
    logger.try_info(&format!(
        "Logger initialized with path: {:?} and level: {:?}",
        logger.path(),
        logger.level()
    ))?;

    Ok(())
}
