jaypipes / ghw

Go HardWare discovery/inspection library
Apache License 2.0
1.65k stars 183 forks source link

Add timestamp to log #390

Open peter81git opened 2 weeks ago

peter81git commented 2 weeks ago

For better log management it is required to have a timestamp for every line in the log file. Is it possible to add it like [2024-11-11T18:52:27.937395+00:00] WARNING: failed to determine nodes: open /sys/devices/system/node: no such file or directory ? Thank you.

jaypipes commented 2 weeks ago

@peter81git Hi! Hey, just FYI I'm at KubeCon NA 2024 all week and pretty busy... will try my best to get to this some time in the evening this week. Thanks for your patience!

ffromani commented 2 weeks ago

Hi! It is true that timestamps help, but ghw warnings are meant for exceptional circumstances rather than standard logging. I'd rather let callers pass a go-logr handle to use in ghw packages. This is a much larger effort though.

ffromani commented 2 weeks ago

logr reference: https://github.com/go-logr/logr

ffromani commented 2 weeks ago

While we debate if adding support for go-logr or not, you can use option.WithAlerter (see: https://github.com/jaypipes/ghw/blob/main/pkg/option/option.go#L179) to replace the default logger with one which adds timestamps without needing changes to ghw code