rust-cli / env_logger

A logging implementation for `log` which is configured via an environment variable.
https://docs.rs/env_logger
Apache License 2.0
825 stars 127 forks source link

Turning on specific log statements #144

Open matklad opened 5 years ago

matklad commented 5 years ago

That's going on to be a crazy dream rather than specific issue, but nonetheless ...

I personally use eprintln rather than log::debug for debugging. log::debug seems like a better thing in theory (because you can reuse the same high-quality logs between different debugging sessions, and you don't need to recompile), but in practice launching code with logging enabled can be hard, and you typically get way more logging output than you need, even if you use filters.

Ideally, you'd just narrow-down logging to a single log statement, but that makes it even harder to set the relevant RUST_LOG env var.

I think this is a case where an IDE can be of great help! I imagine a feature, similar to debugger breakpoints in a graphical debugger, where you can enabled and disable log statements in the IDE on a case by case basis.

Specifically, an IDE maintains a list of active log statements, and, when the cursor is on the log::debug! call, the IDE offers an action to add/remove this particular statement from the set. When a user launches a test or a binary from withing IDE, IDE, known all active log statements, their positions and paths, construct an RUST_LOG env var, which enables only those selected log statements.

However, I think it's currently not possible to use such fine-grained filtering on the env_logger side. Specifically, I can only filter by module prefix, and by regex for all modules. What I need is either:

Additionally, matching on precis module path, and not prefix, would help as well.

I am not sure if it's worth pursuing this, and if I really have time right now to implement this on the rust-analyzer's side, but I thought that it might be good to log the issue anyway :)

acowley commented 3 years ago

I'd like to be able to use precise module paths rather than prefixes, too. Might that be a smaller carve-out from the broader ideas here?