-
Notifications
You must be signed in to change notification settings - Fork 153
Feature request: time zone aware timestamp in Logger #1774
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
Comments
Note that the issue is marked as |
With v2 released, the issue is back on the backlog and ready to pick up. If anyone from the community is interested in contributing please leave a comment below and feel free to ask any question or clarification. |
@dreamorosi You can assign me on this. |
Thank you for picking this up @arnabrahman! |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
Use case
By default Logger emits logs with timestamps formatted using the UTC timezone. This is the default behavior in Lambda since the
TZ
value is always set toUTC
in the execution environment (source).As a customer however I might want to emit logs that contain timestamps that are formatted according to a different timezone (i.e.
2021-12-12T21:21:08.921+01:00
instead of2021-12-12T21:21:08.921Z
).The Logger utility should be able to take in account the value of the
TZ
environment variable, and if it's different thanUTC
, format the timestamps in the logs accordingly.Solution/User Experience
By default the Lambda environment has the
TZ
variable set to UTC (source), if this is the case logs would be emitted as UTC like they are already. If instead the value of theTZ
env variable is something else, we format the timestamp taking into account the time zone.When in UTC, timestamps are formatted like they are today:
2021-12-12T21:21:08.921Z
(source).When using a time zone, timestamps should be formatted including the timezone offset:
2021-12-12T21:21:08.921+01:00
. The offset can be positive (+
) or negative (-
) and it's followed byHH:MM
- see ISO_8601 spec.Below an example implementation that could be used as basis for the implementation:
Note that the code above is provided only as an example, the implementer should review it and make sure it's correct as well as applying any optimization as needed.
In terms of implementation, the implementer should modify the
LogFormatter.formatTimestamp()
method here so that it uses theenvVarsService
(if present) to fetch the value of theTZ
environment variable. Then, based on the value of the variable, the implementation should be modified to either use the existing formatting, or the new time zone aware one.Alternative solutions
No response
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: