ghw icon indicating copy to clipboard operation
ghw copied to clipboard

Add timestamp to log

Open peter81git opened this issue 1 year ago • 4 comments

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.

peter81git avatar Nov 11 '24 18:11 peter81git

@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!

jaypipes avatar Nov 12 '24 16:11 jaypipes

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 avatar Nov 14 '24 13:11 ffromani

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

ffromani avatar Nov 14 '24 14:11 ffromani

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

ffromani avatar Nov 14 '24 15:11 ffromani