Skip to content

warning occurs #114

Description

@sasaki000

The following warning occurs:

/home/sasaki/workspace/orcas_proj/venv/lib/python3.12/site-packages/logstash/formatter.py:73: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
  tstamp = datetime.utcfromtimestamp(time)

Modify the format_timestamp method around line 73 of logstash/formatter.py as follows:

  • Before the fix
    @classmethod
    def format_timestamp(cls, time):
        tstamp = datetime.utcfromtimestamp(time)
        return tstamp.strftime("%Y-%m-%dT%H:%M:%S") + ".%03d" % (tstamp.microsecond / 1000) + "Z"
  • After correction (sample)
    @classmethod
    def format_timestamp(cls, time):
        from datetime import datetime, timezone  # <-Please write at the beginning of the line
        tstamp = datetime.fromtimestamp(time, tz=timezone.utc)
        return tstamp.strftime("%Y-%m-%dT%H:%M:%S") + ".%03d" % (tstamp.microsecond / 1000) + "Z"

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions