env_logger icon indicating copy to clipboard operation
env_logger copied to clipboard

Support reparsing filters at runtime

Open KodrAus opened this issue 7 years ago • 3 comments

Originally raised in #103

Currently, I don't see a nice way to change logging levels dynamically. (Or is there?). It is not very friendly with log::set_max_level_filter either to able to make even small changes.

Would be nice to be able to make small changes if not full reparse during runtime. It becomes extremely helpful in server environments to be able to to that.

KodrAus avatar Nov 05 '18 04:11 KodrAus

I took a jab at adding support for this and have come up with two prototypes:

  • Non breaking change: Added an RwLock around the filter field of the Logger struct. This approach is simple but there is a read penalty when accessing the filter field anytime something is logged. Code for this approach here
  • Breaking change: Used generics to create a logger that can change filters at runtime or forgo the ability to change at runtime to avoid the read penalty and remain static (basically how it is now). Code for this approach here

For both prototypes, when the logger is built you can get an instance of a new struct called DynamicLogLevel. It has a check_filter_config method that when called, checks a config file and updates the filter if the levels have changed. The contents of this config file should follow the same syntax used for the RUST_LOG env var.

My goal is to start the conversation and possibly see if there are better ways to add support for this.

jose-acevedoflores avatar Apr 10 '21 07:04 jose-acevedoflores

+1 to "this would be nice"

steveklabnik avatar Feb 17 '22 18:02 steveklabnik