desbma / rsop

Simple, fast & configurable tool to open and preview files
MIT License
22 stars 3 forks source link

How to configure logging #6

Closed cskeeters closed 3 months ago

cskeeters commented 3 months ago

When I configured this tool for use with fzf, it outputs logging before launching the associated handler. To turn off the logging, I made the following change:

diff --git a/src/main.rs b/src/main.rs
index 7bc0bc2..db2300f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -76,6 +76,7 @@ fn runtime_mode() -> RsopMode {
fn main() -> anyhow::Result<()> {
    // Init logger
    simple_logger::SimpleLogger::new()
+        .env()
        .init()
        .context("Failed to init logger")?;

and then I could configure the level by launching the program with:

RUST_LOG=ERROR rsp

NOTE: my version of rsop was compiled as a debug target. I don't know if that affects logging or not.

I don't see much in the way of logging configuration documentation in the README.md file. How is log level supposed to be configured?

desbma commented 3 months ago

The log level is currently static at runtime, and filtered at build time in release mode to only keep what is at level info or above: https://github.com/desbma/rsop/blob/f01776e741d97c9a7f7f440d4432e89334a0d62a/Cargo.toml#L17

cskeeters commented 3 months ago

Thanks for the info.

Given https://github.com/desbma/rsop/issues/5, I changed max_level_trace to max_level_error so I can just run the debug release without any additional output.