-
Notifications
You must be signed in to change notification settings - Fork 8
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
suggestion: allow optional tz
parameter for timestamp_fmt
in Layout(s)
#46
Comments
So you want So getting timezones right is kinda tricky, and I think general best practice would be to log everything in UTC, especially if you work across several systems in different timezones. I understand that It would be more convenient if lgr supported converting timezones directly, but if it did that should probably be at global level - so that all Appenders log in the same timezone. I will leave this open, but It might be a while before I get around to work on lgr again because I'm kinda tied up in other projects at the moment. |
I agree that UTC is the best timezone to use for logging timestamps. Is there a recommended approach to configuring the lgr package to log everything in UTC? Currently the lgr package seems to be writing to the local timezone by default. |
No there is not. I'd really like to improve timezone handling in lgr but it seems to be a problem that is a bit convoluted and I'm not yet sure how to go about it. You COULD attach a filter to the logger as a workaround if you really need UTC timestamps right now, but this is probably something I should support natively:
|
I think I found another workaround that may interest you. Below I simply set the Sys.timezone() to 'UTC' and all timestamps using Sys.time() will be returned in the 'UTC' timezone with appropriate offset from my local time. `
` OUTPUT [1] "America/New_York" |
I am not sure what |
Sometimes it's helpful to have logs across disparate machines output timestamps with the same TZ offset.
Currently, the best way to do this is:
timestamp_fmt
string to something like%FT%T%z
, a proper ISO8601 with TZ offset (%z
).But(!),
base::format.POSIXct
includes atz
parameter; here's the signature:... and lgr's default Layouts simply delegate to that function.
I wonder if it'd be possible to pass on the
tz
argument, or perhaps even more generally simply 'pass the dots' and allowtimestamp_tz
setters to specify a dots (...
) arg that is captured, stored, then spliced into the eventualformat.POSIXct
dispatch.Only a suggestion :-) ... and thanks much for all the work you've put into lgr, it's quite nice!
The text was updated successfully, but these errors were encountered: