Attribute Macro try_init

Source
#[try_init]
Expand description

An attribute to initialize a logger with various options.

§Attributes

  • test: Sets the test name for the logger. Log output will be written to a file named ../logs/{test_name}.log.
  • file: Sets the file path for the log output.
  • stdio: Enables standard I/O output for the logger.(default: true)
  • level: Sets the log level filter (e.g., TRACE, DEBUG, INFO, WARN, ERROR. default: TRACE).

§Examples

  • Trace mode + stdio
#[quick_tracing::try_init]
fn main() -> std::io::Result<()> {
    tracing::debug!("Hello, world!");
    Ok(())
}
  • Debug mode + Output file(If there is no parent directory, it will automatically create one.)
#[quick_tracing::try_init(level= "DEBUG", file = "./log/test.log", stdio = false)]
fn main() -> std::io::Result<()> {
    tracing::debug!("Hello, world!");
    Ok(())
}