daboross/fern

Is it possible to enable mask logging by a module name using an environment variable?

iddm opened this issue · 4 comments

iddm commented

In the Qt framework it is possible to set a mask which is used for filtering the logs:

    QT_LOGGING_RULES="*.debug=false;driver.usb.debug=true"

That would be nice if fern supported this as well, by using, for example, the record.module_path() as a compare against.

Hi! I believe what you're looking for is the level_for method. It allows setting log levels on a per-module basis.

There's also a general filter method if you want to write a more fine-grained or custom filter.

If you want to expose either of these as as environment variable, unfortunately you'll need to write that code yourself. Fern provides just enough of an API to tell the logging system what to filter, but not much more than that. Still, if it makes sense for your app I think it should definitely be possible to parse an env variable into a list of modules and log levels, then pass those modules and log levels into fern using level_for!

Okay, that answers my question. Though, I'd like to have this feature in the fern itself as this would be much more convenient for me, I understand, that this is not the policy this project follows.

Thank you for your help.

No problem. And thank you for asking this!

I think there could definitely be room for things like this, but I'd want to design a suite of options, and probably put it either under a separate crate (fern-recipes) or a feature flag. One thing I've wanted for a while is a combinator compatible with env_logger's RUST_LOG variable- but, I haven't had the time to create that, or to really think through a good way to add these in general to fern yet.

No problem. And thank you for asking this!

I think there could definitely be room for things like this, but I'd want to design a suite of options, and probably put it either under a separate crate (fern-recipes) or a feature flag. One thing I've wanted for a while is a combinator compatible with env_logger's RUST_LOG variable- but, I haven't had the time to create that, or to really think through a good way to add these in general to fern yet.

It would be nice to have something like that as well :)
What I noticed in other crates is that they sometimes have a feature like "extra" under which they implement all extra-stuff which is not compiled by default, maybe there is a way to implement things like that in the same manner.
Just saying, not asking.
Thank you for your comment. If I have time, I will try adding it myself and then propose a pull request for you to see how it aligns with the project in your opinion.