Skip to content

fix: update utcnow for python 3.12 deprecation #107

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ jobs:

strategy:
matrix:
python-version: ["3.7", "3.8", "3.9"]
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]

steps:
- name: Set up Python ${{ matrix.python-version }}
1 change: 0 additions & 1 deletion json_logging/__init__.py
Original file line number Diff line number Diff line change
@@ -61,7 +61,6 @@ def config_root_logger():
if ENABLE_JSON_LOGGING:
ENABLE_JSON_LOGGING_DEBUG and _logger.debug("Update root logger to using JSONLogFormatter")

global _default_formatter
util.update_formatter_for_loggers([logging.root], _default_formatter)


6 changes: 3 additions & 3 deletions json_logging/dto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from json_logging import util

@@ -32,14 +32,14 @@ class DefaultRequestResponseDTO(RequestResponseDTOBase):

def __init__(self, request, **kwargs):
super(DefaultRequestResponseDTO, self).__init__(request, **kwargs)
utcnow = datetime.utcnow()
utcnow = datetime.now(timezone.utc)
self._request_start = utcnow
self["request_received_at"] = util.iso_time_format(utcnow)

# noinspection PyAttributeOutsideInit
def on_request_complete(self, response):
super(DefaultRequestResponseDTO, self).on_request_complete(response)
utcnow = datetime.utcnow()
utcnow = datetime.now(timezone.utc)
time_delta = utcnow - self._request_start
self["response_time_ms"] = int(time_delta.total_seconds()) * 1000 + int(time_delta.microseconds / 1000)
self["response_sent_at"] = util.iso_time_format(utcnow)
4 changes: 2 additions & 2 deletions json_logging/formatters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sys
import traceback
from datetime import datetime
from datetime import datetime, timezone

import json_logging

@@ -61,7 +61,7 @@ def format(self, record):
return json_logging.JSON_SERIALIZER(log_object)

def _format_log_object(self, record, request_util):
utcnow = datetime.utcnow()
utcnow = datetime.now(timezone.utc).replace(tzinfo=None)

base_obj = {
"written_at": json_logging.util.iso_time_format(utcnow),
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Global fixtures and settings for the pytest test suite"""
import sys
import os
from helpers import constants

# Add test helper modules to search path with out making "tests" a Python package
sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))

if sys.version_info.major > 3 or (sys.version_info.major == 3 and sys.version_info.minor >= 12):
constants.STANDARD_MSG_ATTRIBUTES.add('taskName')
2 changes: 1 addition & 1 deletion tests/smoketests/sanic/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sanic
sanic==20.3.0
requests
pytest
-e .