diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 9ea5d9d..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Test python-json-logger - -on: - push: - branches: - - master - workflow_dispatch: - inputs: - logLevel: - description: 'Log level' - required: true - default: 'warning' - type: choice - options: - - info - - warning - - debug - pull_request: - types: [opened, reopened] - -jobs: - test: - runs-on: "ubuntu-20.04" #Moving down to 20.04 (latest is 22.04) because of python3.6 support - strategy: - fail-fast: false - matrix: - python-version: ["pypy-3.8", "pypy-3.9", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] - - steps: - - uses: actions/checkout@v3 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install tox tox-gh-actions - - - name: Test with tox - run: tox diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index ee269e8..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Release python-json-logger build - -on: - release: - types: [ created ] - - workflow_dispatch: - -jobs: - publish: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine typing_extensions - - - name: Build and Upload to PyPi - run: | - python setup.py sdist bdist_wheel - python -m twine upload dist/* - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml new file mode 100644 index 0000000..91a22d4 --- /dev/null +++ b/.github/workflows/test-suite.yml @@ -0,0 +1,47 @@ +name: Test python-json-logger + +on: + push: + branches: + - main + + pull_request: + branches: + - main + +jobs: + test: + name: "Python ${{matrix.python-version}} ${{ matrix.os }}" + runs-on: "${{ matrix.os }}" + strategy: + matrix: + python-version: + - "pypy-3.7" + - "pypy-3.8" + - "pypy-3.9" + - "pypy-3.10" + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + os: + - ubuntu-latest + - windows-latest + - macos-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox tox-gh-actions + + - name: Test with tox + run: tox diff --git a/setup.py b/setup.py index 74320b3..a5a84de 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name="python-json-logger", - version="2.0.7", + version="3.0.0.dev1", url="http://github.com/madzak/python-json-logger", license="BSD", include_package_data=True, @@ -21,7 +21,7 @@ package_data={"pythonjsonlogger": ["py.typed"]}, packages=find_packages("src", exclude="tests"), # https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires - python_requires=">=3.6", + python_requires=">=3.7", test_suite="tests.tests", classifiers=[ 'Development Status :: 6 - Mature', @@ -30,12 +30,13 @@ 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Topic :: System :: Logging', ] ) diff --git a/src/pythonjsonlogger/jsonlogger.py b/src/pythonjsonlogger/jsonlogger.py index 519a64d..2b72f54 100644 --- a/src/pythonjsonlogger/jsonlogger.py +++ b/src/pythonjsonlogger/jsonlogger.py @@ -2,12 +2,14 @@ This library is provided to allow standard python logging to output log data as JSON formatted strings """ + import logging import json import re import traceback import importlib from datetime import date, datetime, time, timezone +import sys from typing import Any, Callable, Dict, List, Optional, Tuple, Union from inspect import istraceback @@ -16,7 +18,8 @@ # skip natural LogRecord attributes # http://docs.python.org/library/logging.html#logrecord-attributes -RESERVED_ATTRS: Tuple[str, ...] = ( +# Changed in 3.0.0, is now list[str] instead of tuple[str, ...] +RESERVED_ATTRS: List[str] = [ "args", "asctime", "created", @@ -39,7 +42,11 @@ "stack_info", "thread", "threadName", -) +] + +if sys.version_info >= (3, 12): + # taskName added in python 3.12 + RESERVED_ATTRS.append("taskName") OptionalCallableOrStr = Optional[Union[Callable, str]] @@ -63,9 +70,7 @@ def merge_record_extra( rename_fields = {} for key, value in record.__dict__.items(): # this allows to have numeric keys - if key not in reserved and not ( - hasattr(key, "startswith") and key.startswith("_") - ): + if key not in reserved and not (hasattr(key, "startswith") and key.startswith("_")): target[rename_fields.get(key, key)] = value return target @@ -79,10 +84,10 @@ def default(self, obj): if isinstance(obj, (date, datetime, time)): return self.format_datetime_obj(obj) - elif istraceback(obj): + if istraceback(obj): return "".join(traceback.format_tb(obj)).strip() - elif type(obj) == Exception or isinstance(obj, Exception) or type(obj) == type: + if type(obj) == Exception or isinstance(obj, Exception) or type(obj) == type: return str(obj) try: @@ -117,9 +122,9 @@ def __init__( prefix: str = "", rename_fields: Optional[dict] = None, static_fields: Optional[dict] = None, - reserved_attrs: Tuple[str, ...] = RESERVED_ATTRS, + reserved_attrs: Union[Tuple[str, ...], List[str]] = RESERVED_ATTRS, timestamp: Union[bool, str] = False, - **kwargs: Any + **kwargs: Any, ): """ :param json_default: a function for encoding non-standard objects @@ -197,8 +202,7 @@ def parse(self) -> List[str]: if self._fmt: return formatter_style_pattern.findall(self._fmt) - else: - return [] + return [] def add_fields( self, diff --git a/tox.ini b/tox.ini index 8eafd27..b611567 100644 --- a/tox.ini +++ b/tox.ini @@ -1,17 +1,19 @@ [tox] requires = tox>=3 -envlist = lint, type, pypy{38,39}, py{36,37,38,39,310,311} +envlist = lint, type, pypy{37,38,39,310}, py{37,38,39,310,311,312} [gh-actions] python = + pypy-3.7: pypy37 pypy-3.8: pypy38 pypy-3.9: pypy39 - 3.6: py36 + pypy-3.10: pypy310 3.7: py37 3.8: py38 3.9: py39 3.10: py310 - 3.11: py311, type + 3.11: py311 + 3.12: py312, type [testenv] description = run unit tests