dcgm-exporter icon indicating copy to clipboard operation
dcgm-exporter copied to clipboard

feat: add log formatting

Open pintohutch opened this issue 1 year ago • 1 comments

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.

pintohutch avatar Dec 30 '24 21:12 pintohutch

Friendly ping @glowkey - is this something that could be useful?

pintohutch avatar Mar 11 '25 14:03 pintohutch

Yes, can it be adjusted to handle the user specified log-level

glowkey avatar Mar 31 '25 20:03 glowkey

Oh, and thank you for the submission!

glowkey avatar Mar 31 '25 20:03 glowkey

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.

pintohutch avatar Apr 01 '25 12:04 pintohutch

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?

glowkey avatar Apr 01 '25 13:04 glowkey

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...

pintohutch avatar Apr 01 '25 14:04 pintohutch

Ah - I think it just needed to route to os.Stderr - patched that and tested it. PTAL.

pintohutch avatar Apr 01 '25 15:04 pintohutch

Did a few other fixes to handle debug logging and automaxprocs properly.

pintohutch avatar Apr 01 '25 16:04 pintohutch

Friendly ping @glowkey

pintohutch avatar Apr 14 '25 22:04 pintohutch