Repository: iqlusioninc/abscissa (language: rust)

Issue:
RUST_LOG support.
Per https://github.com/iqlusioninc/abscissa/pull/154#issuecomment-559244285, `RUST_LOG` support for `tracing` was left unresolved. It'd be nice to have it for, e.g., https://github.com/ZcashFoundation/zebra/issues/98 (cc @dconnolly)

One design question I'm not sure of: what should be the priority order of `RUST_LOG` and a config setting? Should `RUST_LOG` be overridden by a config option or vice versa? If `RUST_LOG` is overridden by a config option, does the presence of a config default prevent `RUST_LOG` from ever being used?


Discussion / hints:
Personally I think `RUST_LOG` should override the config, but I'd be curious to look at some other ecosystem examples of how that's handled.

In general, having `RUST_LOG` working would be great!
For whatever it's worth (very little), it seems slightly easier to implement the other behavior: https://github.com/iqlusioninc/abscissa/pull/154#issuecomment-559243884
Ok, maybe start with what's easy to implement, and we can revisit it if it turns out to be an issue
I think cargo generally prioritizes env variables over configs so I agree with `RUST_LOG` taking top priority

Fix patch:
diff --git a/cli/src/commands/new.rs b/cli/src/commands/new.rs
index 86e68bb3..2350d529 100644
--- a/cli/src/commands/new.rs
+++ b/cli/src/commands/new.rs
@@ -52,7 +52,7 @@ impl Runnable for NewCommand {
         template_files.sort_by(|a, b| a.name().cmp(b.name()));
 
         for template_file in &template_files {
-            self.render_template_file(&app_template, &template_file, &app_properties)
+            self.render_template_file(&app_template, template_file, &app_properties)
                 .unwrap_or_else(|e| fatal_error(e));
         }
 
@@ -168,7 +168,7 @@ impl NewCommand {
             )
         })?;
 
-        app_template.render(template_file, &app_properties, &mut output_file)?;
+        app_template.render(template_file, app_properties, &mut output_file)?;
         status_ok!("Created", "new file: {}", output_path_rel.display());
 
         Ok(())
diff --git a/core/src/trace/config.rs b/core/src/trace/config.rs
index 32ccf924..152a25de 100644
--- a/core/src/trace/config.rs
+++ b/core/src/trace/config.rs
@@ -15,7 +15,16 @@ impl Config {
 
 impl Default for Config {
     fn default() -> Self {
-        "info".to_owned().into()
+        match std::env::var("RUST_LOG") {
+            Ok(val) => {
+                if val.is_empty() {
+                    val.into()
+                } else {
+                    "info".to_owned().into()
+                }
+            }
+            Err(_) => "info".to_owned().into(),
+        }
     }
 }
 


Test patch: