aboutsummaryrefslogtreecommitdiffstats
path: root/cli/template/src
diff options
context:
space:
mode:
authormurilo ijanc2025-11-22 11:32:44 -0300
committermurilo ijanc2025-11-22 11:32:44 -0300
commit2c55d20a05981d8e7073a8c433a07f9f1dc08a54 (patch)
tree7729158b7a23fd3cb2ae8fde28fb0b87c0147bc6 /cli/template/src
parent70441f087263395b78bb70888bbb7de7574e4ff9 (diff)
downloadtemplates-main.tar.gz
Add placeholder project-diagnosis possible choice is log or tracingHEADmain
Diffstat (limited to 'cli/template/src')
-rw-r--r--cli/template/src/main.rs39
1 files changed, 38 insertions, 1 deletions
diff --git a/cli/template/src/main.rs b/cli/template/src/main.rs
index b496ebd..e544de3 100644
--- a/cli/template/src/main.rs
+++ b/cli/template/src/main.rs
@@ -16,7 +16,12 @@
use anyhow::Result;
use clap::{ArgAction, Parser};
-use log::{LevelFilter, info, debug};
+{% if project-diagnosis == "log" -%}
+use log::{debug, info};
+{% else -%}
+use tracing::{debug, info};
+use tracing_subscriber::EnvFilter;
+{% endif %}
const VERSION: &str = concat!(
env!("CARGO_PKG_VERSION"),
@@ -54,8 +59,16 @@ fn main() -> Result<()> {
Ok(())
}
+{% if project-diagnosis == "log" -%}
+/// Initialize log based on RUST_LOG and the CLI verbosity.
+///
+/// Rules:
+/// - If RUST_LOG is set, it is fully respected.
+/// - If RUST_LOG is not set and verbose == 0 -> INFO level.
+/// - If RUST_LOG is not set and verbose > 0 -> DEBUG level.
fn init_logger(verbose: u8) {
use std::io::Write;
+ use log::LevelFilter;
if std::env::var_os("RUST_LOG").is_some() {
env_logger::builder()
@@ -76,3 +89,27 @@ fn init_logger(verbose: u8) {
})
.init();
}
+{% else -%}
+/// Initialize tracing based on RUST_LOG and the CLI verbosity.
+///
+/// Rules:
+/// - If RUST_LOG is set, it is fully respected.
+/// - If RUST_LOG is not set and verbose == 0 -> INFO level.
+/// - If RUST_LOG is not set and verbose > 0 -> DEBUG level.
+fn init_logger(verbose: u8) {
+ if std::env::var_os("RUST_LOG").is_some() {
+ tracing_subscriber::fmt()
+ .with_env_filter(EnvFilter::from_default_env())
+ .init();
+ return;
+ }
+
+ let filter = if verbose > 0 {
+ EnvFilter::new("debug")
+ } else {
+ EnvFilter::new("info")
+ };
+
+ tracing_subscriber::fmt().with_env_filter(filter).init();
+}
+{% endif %}