loggo icon indicating copy to clipboard operation
loggo copied to clipboard

loggo displays logs in UTC and not in local time

Open SR-G opened this issue 4 years ago • 1 comments

Hello, Thanks for this package, it seems quite close to what i need - a simple logger system for golang.

I just have one issue : default formatter outputs everything with wrong time, for example, on my system (french hour in UTC+2) :

16:25 sergio@solaris ~/% date
Sat Jul 24 04:25:47 PM CEST 2021
16:25 sergio@solaris ~/% make run
2021-07-24 14:26:02 INFO  <myprogram>.go:174 <log from loggo>

(system time = 16:25pm, but loggo is display 14:26pm)

Edit : i know this can be overridden by changing formatter, but an option would be more out-of-the-box, instead of having to override DefaultFormatter

loggo.ReplaceDefaultWriter(loggo.NewSimpleWriter(os.Stderr, LocalLoggoFormatter))

(...)

func LocalLoggoFormatter(entry loggo.Entry) string {
	ts := entry.Timestamp.In(time.Local).Format("2006-01-02 15:04:05")
	// Just get the basename from the filename
	filename := filepath.Base(entry.Filename)
	return fmt.Sprintf("%s %s %s %s:%d %s", ts, entry.Level, entry.Module, filename, entry.Line, entry.Message)
}

SR-G avatar Jul 24 '21 14:07 SR-G

you should be able to change the default formatter by updating the default writer. You can see the default formatter here: https://github.com/juju/loggo/blob/master/formatter.go

You could write the same thing but changing Timestamp.In(time.UTC) to Timestamp.In(time.Local).

And then your writer becomes: localTimeWriter := loggo.NewSimpleWriter(os.Stderr, localTimeFormatter)

loggo.ReplaceDefaultWriter(localTimeWriter)

On Sat, Jul 24, 2021 at 10:27 AM Serge @.***> wrote:

Hello, Thanks for this package, it seems quite close to what i need - a simple logger system for golang.

I just have one issue : default formatter outputs everything with wrong time, for example, on my system (french hour in UTC+2) :

16:25 @.*** ~/% date Sat Jul 24 04:25:47 PM CEST 2021 16:25 @.*** ~/% make run 2021-07-24 14:26:02 INFO .go:174

(system time = 16:25pm, but loggo is display 14:26pm)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/juju/loggo/issues/44, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABRQ7OGZ73DIXJGQRZ5HVTTZLEWPANCNFSM5A5Q25LQ .

jameinel avatar Jul 28 '21 19:07 jameinel