Skip to content

Commit

Permalink
Replace pytz by zoneinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke authored and lnagel committed Sep 18, 2024
1 parent 46d4c6f commit 013de7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions django_datadog_logger/formatters/datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import typing
from logging import LogRecord

try:
import zoneinfo
except ImportError:
from backports import zoneinfo

import json_log_formatter
import pytz
from django.conf import settings
from django.core.exceptions import DisallowedHost
from django.http.request import split_domain_port, HttpRequest
Expand Down Expand Up @@ -77,7 +81,9 @@ def json_record(self, message: str, extra: typing.Dict, record: LogRecord) -> ty
"logger.name": record.name,
"logger.thread_name": record.threadName,
"logger.method_name": record.funcName,
"date": pytz.utc.localize(datetime.datetime.utcfromtimestamp(record.created)).isoformat(),
"date": (
datetime.datetime.utcfromtimestamp(record.created).replace(tzinfo=zoneinfo.ZoneInfo("UTC")).isoformat()
),
"status": record.levelname,
}

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JSON-log-formatter
Django
djangorestframework
pytz
backports.zoneinfo;python_version<"3.9"

0 comments on commit 013de7f

Please sign in to comment.