01_macro/
01-macro.rs

1// All log macros and common types are under `spdlog::prelude` module.
2use spdlog::prelude::*;
3
4fn main() {
5    // Writes a log at "info" level, and this log will be processed by the global
6    // default logger - It will be output to `stdout`.
7    info!("program started");
8
9    // They will be output to `stderr`.
10    let file = "config.json";
11    error!("failed to open file: {}", file);
12    warn!("undetermined locale, defaults to `en_US.UTF-8`");
13
14    // Level "trace" and "debug" will be ignored by default, you can modify the
15    // level filter of the global default logger to enable all levels.
16    let verbose = true;
17    if verbose {
18        spdlog::default_logger().set_level_filter(LevelFilter::All);
19    }
20
21    trace!("position x: {}, y: {}", 11.4, -5.14);
22    // Or if you prefer structured logging.
23    trace!("position", kv: { x = 11.4, y = -5.14 });
24}