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

Timezone aware timestamp logging #381

Closed
bml1g12 opened this issue Apr 4, 2021 · 3 comments
Closed

Timezone aware timestamp logging #381

bml1g12 opened this issue Apr 4, 2021 · 3 comments
Labels
feature-request feature request
Milestone

Comments

@bml1g12
Copy link

bml1g12 commented Apr 4, 2021

Describe the solution you'd like

I would like to be able to easily log in a timezone aware manner; a typical use case being to always log in UTC time, regardless of where the code is run. At present, the Powertools Logger() uses localtime for the timestamp field as under the hood it uses the asctime() method.

Describe alternatives you've considered
I raised this issue as a documentation query at first #379 and @heitorlessa kindly helped me find a workaround to this there using monkeypatching or overwritting the formatter.

It can be a new feature for Logger to have a flag to convert to UTC or a given offset, which I agree would be a useful feature as I imagine many users would desire the ability to ensure the timestamp is UTC. For example, this is actually a requirement if one wished to log strictly according to the ISO 8601 standard.

@bml1g12 bml1g12 added feature-request feature request triage Pending triage from maintainers labels Apr 4, 2021
@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Apr 7, 2021
@heitorlessa heitorlessa added this to the 1.15.0 milestone Apr 9, 2021
@heitorlessa
Copy link
Contributor

heitorlessa commented Apr 9, 2021

Thanks again for creating the feature request @bml1g12 - In the meantime, I've updated the docs with that fix until we decide on the best way to implement this for everyone ;)

https://awslabs.github.io/aws-lambda-powertools-python/develop/core/logger/#setting-timestamp-to-utc

cc @saragerion @pankajagrawal16 this is a great chance on using our brand new RFCs repo and make it public - I'm sure this will be asked at some point for Typescript and Java too

@saragerion
Copy link

saragerion commented Apr 9, 2021

@bml1g12 I completely agree with your proposal. Local time is calculated based on the context of the current machine and that might be different from the developer local time.
It's important that all logs generate use the same common "timezone".

The TypeScript Powertool is supporting ISO 8601 by default, and the timezone is always zero UTC offset. Developers can choose to customize the format if they want.
What do you think?

@heitorlessa heitorlessa added the pending-release Fix or implementation already in dev waiting to be released label Apr 26, 2021
@heitorlessa heitorlessa removed the pending-release Fix or implementation already in dev waiting to be released label May 6, 2021
@heitorlessa
Copy link
Contributor

This is now out in 1.15.0: #423.

logger = Logger(service="example", utc=True) ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request
Projects
None yet
Development

No branches or pull requests

3 participants