daboross / fern

Simple, efficient logging for Rust
MIT License
848 stars 51 forks source link

Question: Is it possible to initialize logging via a configuration file? #60

Open apatniv opened 4 years ago

apatniv commented 4 years ago

I don't see any example of this in docs.rs.

Thanks for writing a very useful library.

daboross commented 4 years ago

This isn't a feature of fern - it only offers rust-syntax-based initialization.

log4rs is the best configuration-based logger I know of today. If you need it, one-way interop should be possible by passing a Box<dyn Log> created from log4rs into fern::Dispatch::chain.

Another alternative is to build your own configuration, and translate that into fern calls. This is probably substantially more work, but if you just need something simple like setting the maximum log level, it should be doable.

Glad the library has been useful! :)

apatniv commented 4 years ago

Thanks for the response. I will look into your suggestions.

Do you think adding support for this in the future is a good idea?

daboross commented 4 years ago

In my view, I think it would be more work than what it's worth.

Fern does a relatively good job at its two jobs: first, a logging implementation, and second, an rusty interface to configure that implementation. If we added a configuration-based interface, then it could use the implementation, but it'd probably be completely separate from the rusty interface. I don't think that fern's implementation is anything that special, so there wouldn't be too much benefit over configuration interfaces which already exist, like log4rs.