Skip to content

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

@SR-G

Description

@SR-G

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions