Skip to content

Conversation

cevaris
Copy link

@cevaris cevaris commented May 10, 2016

Looking at logger.go, seems we default to Local time. Make sense for some, but it would be nice to be able to correlate logs with UTC time based events.

var (
    // Sequence number is incremented and utilized for all log records created.
    sequenceNo uint64

    // timeNow is a customizable for testing purposes.
    timeNow = time.Now
)

This PR adds and exposes a SetTimeNow(func() time.Time) function to provide the end user a choice whether to log using the default Local time, or UTC, or MST, etc.

func init() {
    backend1 := logging.NewLogBackend(os.Stderr, "", 0)
    backend1Leveled := logging.AddModuleLevel(backend1)

    // Log UTC time, default is Local
    logging.SetTimeNow(time.Now().UTC)

    logging.SetBackend(backend1Leveled)
}

@cevaris cevaris force-pushed the added-timenow-override branch from 913568f to dc70e36 Compare May 10, 2016 02:17
@cevaris
Copy link
Author

cevaris commented Sep 14, 2016

any thoughts @op ?

@smvv
Copy link

smvv commented Jul 17, 2017

@op can you merge this PR? I would like to use the UTC timezone while formatting as well

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

Successfully merging this pull request may close these issues.

2 participants