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

warning occurs #114

Open
sasaki000 opened this issue Dec 14, 2024 · 0 comments
Open

warning occurs #114

sasaki000 opened this issue Dec 14, 2024 · 0 comments

Comments

@sasaki000
Copy link

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant