Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loggo displays logs in UTC and not in local time #44

Open
SR-G opened this issue Jul 24, 2021 · 1 comment
Open

loggo displays logs in UTC and not in local time #44

SR-G opened this issue Jul 24, 2021 · 1 comment

Comments

@SR-G
Copy link

SR-G commented Jul 24, 2021

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)
}
@jameinel
Copy link
Member

jameinel commented Jul 28, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants