Skip to content

Log using UTC time #98

@clawconduce

Description

@clawconduce

I have a simple logger setup:

import logging "github.com/op/go-logging"

func main() {
    ...

    log := logging.MustGetLogger(name)

    // Setup the logger
    logBackend := logging.NewLogBackend(os.Stdout, "", 0)
    var format = logging.MustStringFormatter(
        `%{time:2006-01-02 15:04:05.000} : %{level:-6.6s} : %{message}`,
    )
    logging.timeNow = timeNow
    logBackendFormatter := logging.NewBackendFormatter(logBackend, format)
    logging.SetBackend(logBackendFormatter)
}

and I am trying to get it to output timestamps in UTC time, but I do not see a way to do this. I think setting logging.timeNow would work, but this isn't possible because it is not exported. Is there a way to do this? If not, could we support using custom time functions? I'd like to use something like:

func UtcTimeNow() time.Time {
    return time.Now().UTC()
}

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions