feat: add log formatting
We introduce log formatting to support both text and json formats. This can be configured through a CLI flag "log-format" or env var "DCGM_EXPORTER_LOG_FORMAT".
Notably, the log format will capture any DCGM logging that is configured.
We also move the automaxprocs call from an unused import to be explicitly called when starting the dcgm exporter to ensure its logging format honors the configuration.
Friendly ping @glowkey - is this something that could be useful?
Yes, can it be adjusted to handle the user specified log-level
Oh, and thank you for the submission!
Yes, can it be adjusted to handle the user specified log-level
IIUC that is already handled for debug-level only through the DCGM_EXPORTER_DEBUG option. If we wanted more generic log-level handling, that seems like it would require a refactor or deprecation of that option, no?
This change is just focused on the format of the logs - i.e. plaintext or json - regardless of the level.
In my testing this change was incompatible with the Capture mechanism and I wasn't seeing any output in either format. When I disabled Capture then I was able to test the change and toggle between text and json. My test was simply running the binary without any args. How did you test the change?
Hrm - thanks for catching. I believe this was working before the 4.X release, but I see the same thing now.
It may be more involved than I originally thought. I'm less confident how to untangle the Capture mechanism...
Ah - I think it just needed to route to os.Stderr - patched that and tested it. PTAL.
Did a few other fixes to handle debug logging and automaxprocs properly.
Friendly ping @glowkey