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
797 stars 124 forks source link

implements format_file_location #232

Open imlazyeye opened 2 years ago

imlazyeye commented 2 years ago

Implements a new option to the format builder to make the header on logs display the file and line number a log originated from.

I work on a project (a binary) that uses this library and we often have trouble identifying where scattered warnings / debug messages are actually being fired from. The specificity of files + line numbers is more helpful for us, who will never have these logs displayed to an end-user.

I tried to implement this with as small of a footprint as possible, but that does lead to a bit of weirdness with the relationship between the new format_file_location and format_module_path, since they both want control over the header. I have just made it so that attempting to enable both will print out a warning that you can't and then rejects the second request. A more elegant way of handling this may be creating a type that can contain both behaviors (leading to something like format_header_style(HeaderStyle::ModulePath), but I don't love the idea of users having to import a new type.