Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rework on #109#111

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mavwolverine wants to merge6 commits intobobbui:master
base:master
Choose a base branch
Loading
frommavwolverine:upgrade_retry
Open
Show file tree
Hide file tree
Changes fromall 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
12 changes: 6 additions & 6 deletions.github/workflows/code_quality.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install dependencies
Expand All@@ -40,11 +40,11 @@ jobs:

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: "Git checkout"
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All@@ -63,11 +63,11 @@ jobs:

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: "Git checkout"
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 2 additions & 2 deletionsexample/connexion-example/hello.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,11 +14,11 @@
def post_greeting(name):
logger.info("test log statement")
logger.info("test log statement with extra props", extra={'props': {"extra_property": 'extra_value'}})
return 'Hello {name}'.format(name=name)
returnf'Hello {name}'


def exclude_from_request_instrumentation(name):
return 'Hello {name}. this request wont log request instrumentation information'.format(name=name)
returnf'Hello {name}. this request wont log request instrumentation information'


def create():
Expand Down
6 changes: 3 additions & 3 deletionsexample/custom_log_format_request.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@ def _format_log_object(self, record, request_util):
request = record.request_response_data._request
response = record.request_response_data._response

json_log_object = super(CustomRequestJSONLog, self)._format_log_object(record, request_util)
json_log_object = super()._format_log_object(record, request_util)
json_log_object.update({
"customized_prop": "customized value",
})
Expand All@@ -32,10 +32,10 @@ class CustomDefaultRequestResponseDTO(json_logging.dto.DefaultRequestResponseDTO
"""

def __init__(self, request, **kwargs):
super(CustomDefaultRequestResponseDTO, self).__init__(request, **kwargs)
super().__init__(request, **kwargs)

def on_request_complete(self, response):
super(CustomDefaultRequestResponseDTO, self).on_request_complete(response)
super().on_request_complete(response)
self.status = response.status


Expand Down
1 change: 0 additions & 1 deletionjson_logging/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import json
import logging
import sys
Expand Down
6 changes: 3 additions & 3 deletionsjson_logging/dto.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ def __init__(self, request, **kwargs):
invoked when request start, where to extract any necessary information from the request object
:param request: request object
"""
super(RequestResponseDTOBase, self).__init__(**kwargs)
super().__init__(**kwargs)
self._request = request

def on_request_complete(self, response):
Expand All@@ -31,14 +31,14 @@ class DefaultRequestResponseDTO(RequestResponseDTOBase):
"""

def __init__(self, request, **kwargs):
super(DefaultRequestResponseDTO, self).__init__(request, **kwargs)
super().__init__(request, **kwargs)
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)
super().on_request_complete(response)
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)
Expand Down
15 changes: 6 additions & 9 deletionsjson_logging/formatters.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,11 +22,8 @@
except NameError:
basestring = str

if sys.version_info < (3, 0):
EASY_SERIALIZABLE_TYPES = (basestring, bool, dict, float, int, list, type(None))
else:
LOG_RECORD_BUILT_IN_ATTRS.append('stack_info')
EASY_SERIALIZABLE_TYPES = (str, bool, dict, float, int, list, type(None))
LOG_RECORD_BUILT_IN_ATTRS.append('stack_info')
EASY_SERIALIZABLE_TYPES = (str, bool, dict, float, int, list, type(None))


def _sanitize_log_msg(record):
Expand All@@ -45,7 +42,7 @@ class BaseJSONFormatter(logging.Formatter):
base_object_common = {}

def __init__(self, *args, **kw):
super(BaseJSONFormatter, self).__init__(*args, **kw)
super().__init__(*args, **kw)
if json_logging.COMPONENT_ID and json_logging.COMPONENT_ID != json_logging.EMPTY_VALUE:
self.base_object_common["component_id"] = json_logging.COMPONENT_ID
if json_logging.COMPONENT_NAME and json_logging.COMPONENT_NAME != json_logging.EMPTY_VALUE:
Expand DownExpand Up@@ -120,7 +117,7 @@ def format_exception(cls, exc_info):
return ''.join(traceback.format_exception(*exc_info)) if exc_info else ''

def _format_log_object(self, record, request_util):
json_log_object = super(JSONLogFormatter, self)._format_log_object(record, request_util)
json_log_object = super()._format_log_object(record, request_util)

json_log_object.update({
"msg": _sanitize_log_msg(record),
Expand All@@ -144,7 +141,7 @@ class JSONLogWebFormatter(JSONLogFormatter):
"""

def _format_log_object(self, record, request_util):
json_log_object = super(JSONLogWebFormatter, self)._format_log_object(record, request_util)
json_log_object = super()._format_log_object(record, request_util)

if json_logging.CORRELATION_ID_FIELD not in json_log_object:
json_log_object.update({
Expand All@@ -160,7 +157,7 @@ class JSONRequestLogFormatter(BaseJSONFormatter):
"""

def _format_log_object(self, record, request_util):
json_log_object = super(JSONRequestLogFormatter, self)._format_log_object(record, request_util)
json_log_object = super()._format_log_object(record, request_util)

request_adapter = request_util.request_adapter
response_adapter = request_util.response_adapter
Expand Down
1 change: 0 additions & 1 deletionjson_logging/framework/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
# coding=utf-8
1 change: 0 additions & 1 deletionjson_logging/framework/connexion/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import logging
import sys

Expand Down
1 change: 0 additions & 1 deletionjson_logging/framework/fastapi/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@

def is_fastapi_present():
# noinspection PyPep8,PyBroadException
try:
Expand Down
1 change: 0 additions & 1 deletionjson_logging/framework/flask/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import logging

import json_logging
Expand Down
1 change: 0 additions & 1 deletionjson_logging/framework/quart/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import logging
import sys

Expand Down
1 change: 0 additions & 1 deletionjson_logging/framework/sanic/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
# coding=utf-8
import logging
import logging.config

Expand Down
1 change: 0 additions & 1 deletionjson_logging/framework_base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
# coding=utf-8
class BaseRequestInfoExtractor:
"""
Helper class help to extract logging-relevant information from HTTP request object
Expand Down
7 changes: 3 additions & 4 deletionsjson_logging/util.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
# coding=utf-8
import logging
import os
import re
import sys
from datetime import datetime
from datetime import datetime, timezone
from logging import Logger, StreamHandler

import json_logging
Expand DownExpand Up@@ -71,7 +70,7 @@ def validate_subclass(subclass, superclass):
return True


_epoch = datetime(1970, 1, 1)
_epoch = datetime(1970, 1, 1, tzinfo=timezone.utc)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

critical

Making_epoch a timezone-awaredatetime object is a good step towards modernizing the codebase. However, this change will cause aTypeError at runtime. The functionepoch_nano_second will now fail when called with a timezone-naivedatetime object, as it's not possible to subtract a naive from an aware datetime.

For example,json_logging.formatters.BaseJSONFormatter._format_log_object calls it with a naive datetime:

# json_logging/formatters.py:61utcnow=datetime.now(timezone.utc).replace(tzinfo=None)...# json_logging/formatters.py:65"written_ts":json_logging.util.epoch_nano_second(utcnow),

To fix this, you need to ensure that all callers ofepoch_nano_second pass a timezone-awaredatetime object. The most direct fix would be to remove.replace(tzinfo=None) informatters.py, but that change is outside the scope of this diff. Please ensure all call sites are updated to prevent runtime failures.



def epoch_nano_second(datetime_):
Expand All@@ -96,7 +95,7 @@ def currentframe(_no_of_go_up_level):
return sys.exc_info()[_no_of_go_up_level - 1].tb_frame.f_back


class RequestUtil(object):
class RequestUtil:
"""
util for extract request's information
"""
Expand Down
11 changes: 3 additions & 8 deletionssetup.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,12 +3,8 @@

from setuptools import setup, find_packages

version_info_major = sys.version_info[0]
if version_info_major == 3:
long_description = open('README.rst', encoding="utf8").read()
else:
io_open = io.open('README.rst', encoding="utf8")
long_description = io_open.read()
with open('README.rst', encoding="utf8") as f:
long_description = f.read()

setup(
name="json-logging",
Expand All@@ -18,7 +14,7 @@
description="JSON Python Logging",
long_description=long_description,
author="Bob T.",
keywords=["json", "elastic", "python", "python3", "python2", "logging", "logging-library", "json", "elasticsearch",
keywords=["json", "elastic", "python", "python3", "logging", "logging-library", "json", "elasticsearch",
"elk", "elk-stack", "logstash", "kibana"],
platforms='any',
url="https://github.com/thangbn/json-logging",
Expand All@@ -28,7 +24,6 @@
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: System :: Logging',
'Framework :: Flask',
Expand Down
5 changes: 2 additions & 3 deletionstests-performance/benmark_micro.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
# coding=utf-8
import time
import timeit
from datetime import datetime
from datetime import datetime, timezone

utcnow = datetime.utcnow()
utcnow = datetime.now(timezone.utc)

numbers = 1000000
# timeit_timeit = timeit.timeit(lambda: '%04d-%02d-%02dT%02d:%02d:%02dZ' % (
Expand Down
11 changes: 9 additions & 2 deletionstests/helpers/constants.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
"""Constants shared by multiple tests"""

STANDARD_MSG_ATTRIBUTES = {
import sys

_msg_attrs = [
"written_at",
"written_ts",
"msg",
Expand All@@ -11,4 +13,9 @@
"module",
"line_no",
"correlation_id",
}
]

if sys.version_info >= (3, 12):
_msg_attrs.append("taskName")

STANDARD_MSG_ATTRIBUTES = set(_msg_attrs)
2 changes: 1 addition & 1 deletiontests/helpers/handler.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ def __init__(self, level=logging.NOTSET) -> None:
"""Create a new log handler."""
super().__init__(level=level)
self.level = level
self.messages:List[str] = []
self.messages:list[str] = []

def emit(self, record: logging.LogRecord) -> None:
"""Keep the log records in a list in addition to the log text."""
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp