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

Allow user to configure timezone #77

Closed
ryan-ju opened this issue Jun 11, 2018 · 6 comments
Closed

Allow user to configure timezone #77

ryan-ju opened this issue Jun 11, 2018 · 6 comments

Comments

@ryan-ju
Copy link

ryan-ju commented Jun 11, 2018

At the moment, the only way to control time format is the zerolog.TimeFieldFormat.

There should be a way to allow the user to change the timezone of the timestamp.

Example: a user wants to always log in Zulu timezone (Z without timezone), no matter where the server is running. If she sets TimeFieldFormat to 2006-01-02T15:04:05Z, then the timestamp will be wrong if the server is running anywhere other than UTC.

@ghost
Copy link

ghost commented Jun 11, 2018 via email

@ryan-ju
Copy link
Author

ryan-ju commented Jun 11, 2018

@gedw99 I just found a workaround:

TimestampFunc = time.Now

zerolog. TimestampFunc = func() time.Time {
    return time.Now().UTC()
}

@ryan-ju ryan-ju closed this as completed Jun 11, 2018
@ghost
Copy link

ghost commented Jun 11, 2018 via email

@jnovack
Copy link

jnovack commented Jun 21, 2020

Sorry to necro, just posting this for future people (or me when I forget).

To get the local time zone:

zerolog.TimestampFunc = func() time.Time {
	return time.Now().In(time.Local)
}

@ysomad
Copy link

ysomad commented Oct 13, 2022

Sorry to necro, just posting this for future people (or me when I forget).

To get the local time zone:

zerolog.TimestampFunc = func() time.Time {
	return time.Now().In(time.Local)
}

time.Now() by default returning local time

@mamyn0va
Copy link

Is there a way to define the time field format without using a global variable ?
I have a race condition as I run my app both times for testing purpose.

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

4 participants