Explorar o código

fix: default RUST_LOG=info when env var is unset

Uses EnvFilter with try_from_default_env() fallback to 'info', so
info-level log messages are visible without setting RUST_LOG every
time.  RUST_LOG can still override (e.g. RUST_LOG=warn to suppress).
Alexander Korolev hai 4 meses
pai
achega
3d12b851cd
Modificáronse 1 ficheiros con 9 adicións e 4 borrados
  1. 9 4
      src/main.rs

+ 9 - 4
src/main.rs

@@ -59,11 +59,16 @@ fn resolve_config_path(cli_config: &str) -> std::path::PathBuf {
 async fn main() -> Result<()> {
 async fn main() -> Result<()> {
     // Locale: check LANG env var first (macOS sys-locale ignores it).
     // Locale: check LANG env var first (macOS sys-locale ignores it).
     // Normalize "ru_RU.UTF-8" → "ru-RU" for unic-langid.
     // Normalize "ru_RU.UTF-8" → "ru-RU" for unic-langid.
-    let locale = std::env::var("LANG").ok().map(|l| {
-        l.split('.').next().unwrap_or(&l).replace('_', "-")
-    });
+    let locale = std::env::var("LANG")
+        .ok()
+        .map(|l| l.split('.').next().unwrap_or(&l).replace('_', "-"));
     let _ = fluent_i18n::set_locale(locale.as_deref());
     let _ = fluent_i18n::set_locale(locale.as_deref());
-    tracing_subscriber::fmt::init();
+    tracing_subscriber::fmt()
+        .with_env_filter(
+            tracing_subscriber::EnvFilter::try_from_default_env()
+                .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
+        )
+        .init();
     let cli = Cli::parse();
     let cli = Cli::parse();
 
 
     let config_path = resolve_config_path(&cli.config);
     let config_path = resolve_config_path(&cli.config);