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

Added SetTimeNow function to override global timeNow func #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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