Closed timou closed 6 years ago
I believe you can implement a log15.Handler
that updates the Record.Time
field to have UTC time without adding any methods to the default logger. I believe the code would look something like this:
func UTCHandler(h log15.Handler) log15.Handler {
return log15.FuncHandler(func(r *log15.Record) error {
r.Time = r.Time.UTC()
return h.Log(r)
})
}
This is a super idea, and I wish I'd thought of it! Thanks Chris.
We have a requirement to have log times in UTC. The default Logger implementation logs in localtime, and cannot, I believe, be easily changed. The solution I used was to re-implement the default logger, just to change one line in the
logger.write
method to usetime.Now().UTC()
instead oftime.Now()
.May I propose that, without changing the
Logger
interface, we add aSetUTC(v bool)
method to the default logger? It would default tofalse
.I am happy to contribute this if others think it is worthwhile.