I have a few programs that need two different types of logging: production logging and detailed development logging.
The idea is that customers running the programs in production only use
env_logger). If they run into some really difficult-to-track-down problems, and we exhaust all other means of finding the issue, they are given instructions on how to enable "dev logs" (i.e. tracing, in this case).
The 'log' logging is always directed to a platform-specific output. The trace logging is meant to be able to be output to the console or to a file.
I'm going to be honest: I find the tracing crate to be quite overwhelming, and I'm pretty sure it is wildly over-competent for our modest use-case. With that said, it has been serving us well so far.
In earlier project we haven't supported outputting trace logs to a file, which is why I'm writing this post. We having been run
tracing next to each other without any issues, but when I wrote a function to initialize tracing to a file,
env_logger panics because it is called twice.
The tracing-to-file initialization looks like this:
tracing_subscriber::fmt() .with_writer(f) .with_ansi(false) .with_max_level(level) .with_timer(timer) .init();
What do I need to avoid doing with
tracing-subscriber to make sure it doesn't step on the toes of
env_logger? (Note that if I enable tracing output to the console rather than the file everything works fine).