Skip to content

Timezone aware timestamp logging #381

Closed

Description

@bml1g12

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.

Activity

  1. added this to the 1.15.0 milestone on Apr 9, 2021
  2. heitorlessa commented on Apr 9, 2021

    @heitorlessa
    Contributor

    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

  3. saragerion commented on Apr 9, 2021

    @saragerion

    @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?

  4. removed
    pending-releaseFix or implementation already in dev waiting to be released
    on May 6, 2021
  5. heitorlessa commented on May 6, 2021

    @heitorlessa
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions