Can I put an env_logger to a file as one output of a combined logger?
Use case: Log messages in a GUI program go to combined_logger. ERROR and WARN messages go to to a window. Right now, INFO and above go to a file. That works. I want to make what goes to a file configurable with an environment variable, env-logger style. Is that easy to do?
I need selective logging. I have a GUI program with WGPU, and WGPU generates INFO level logging on every frame. I need to suppress that, or I get gigabytes of log files. I need to see INFO level logging from just what I'm currently working on.
env-logger is the right idea on filtering. It's that the output options are too limited. The developers looked at offering logging to a file, but then got stuck thinking about long-lived programs, log file rotation, and such.
I already have the code set to be buildable with "tracy" on, but that's a different mechanism. Here, I just need module-level filtering for log items.
The reason env_logger won't play with combined_logger is that combined_logger tracks the highest log level needed by any component logger. So unwanted messages don't get evaluated, and that's cheap. Env_logger requires evaluating a regular expression for each item, and that's expensive if you have a lot of log level log::trace! or log::debug! calls. Env_logger is really for systems where, in production, logging is off.
Env_logger's inability to write to a pipe or file seems to come from a bikeshedding problem. There are people who really like colors in their logs. But there is disagreement over how to represent colored text in log files. ANSI terminal controls? VT100? HTML? So, due to a change in the coloring module, output to a pipe was taken out.
So, for now, I have a setup where, if the environment variable for env_logger is present, env_logger is used and output goes to standard error, which I send to a file. This is enough that I can debug. If no environment variable is present, errors go to a window and errors and warnings go to a log file, using combined_logger. It's an OK workaround for now.