loggerv
loggerv copied to clipboard
Filters and RUST_LOG support
This pull request contains changes to implement the filter
method and support for inheriting logging configuration from the environment via the RUST_LOG
variable, similar to the env_logger crate as discussed in #13. In fact, the env_logger crate already has extensive environment and filter support that is exposed in the public API for re-use in other loggers. Thus, the functionality is re-used in this logger.
The base_level
method has been removed because that specific functionality is now covered by using the RUST_LOG
environment variable. However, a side effect of this implementation is that the default log level is ERROR, not WARN. I cannot figure out a good way to change this default without causing odd or unexpected behavior related to verbosity and the use of the RUST_LOG
environment variable when no filters are applied. The tradeoff is that all filter-related functionality that is implemented in the env_logger is also implemented in this logger without duplicating efforts.
Other than the removal of the base_level
method, the rest of the public API remains the same, but the internals have changed significantly. Based on initial tests and examples, the functionality and behavior is the same, but the source code contains numerous changes. Most notably, an internal logger is used with closures for the logging component. This avoids weirdness with the builder pattern and the filter builder from the env_logger crate, and it avoids having a bunch of Option
types for field members to the logger. The env_logger crate uses a similar implementation and style.
I have also added a new example that shows using the new filter
method with the clap-rs crate. I am not sure if the new functionality yields the desired and expected behavior with relation to the RUST_LOG
support, so this should be viewed as a first attempt and some additional refinement might be needed.