Skip to content

Commit 19bfb64

Browse files
authored
Update Supported Python Versions (#2)
This updates the supported versions of python including those run in the CI test suite. - Python versions 3.7-3.13 - Drops 3.6 - PYPY 3.7-3.10 - Adds MacOS and Windows to test matrix - Add `taskName` to `RESERVED_ATTRS` (fixes: #3 )
1 parent 3dd0257 commit 19bfb64

File tree

6 files changed

+71
-92
lines changed

6 files changed

+71
-92
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/test-suite.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Test python-json-logger
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
test:
14+
name: "Python ${{matrix.python-version}} ${{ matrix.os }}"
15+
runs-on: "${{ matrix.os }}"
16+
strategy:
17+
matrix:
18+
python-version:
19+
- "pypy-3.7"
20+
- "pypy-3.8"
21+
- "pypy-3.9"
22+
- "pypy-3.10"
23+
- "3.7"
24+
- "3.8"
25+
- "3.9"
26+
- "3.10"
27+
- "3.11"
28+
- "3.12"
29+
os:
30+
- ubuntu-latest
31+
- windows-latest
32+
- macos-latest
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- uses: actions/setup-python@v5
38+
with:
39+
python-version: ${{ matrix.python-version }}
40+
41+
- name: Install dependencies
42+
run: |
43+
python -m pip install --upgrade pip
44+
pip install tox tox-gh-actions
45+
46+
- name: Test with tox
47+
run: tox

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="python-json-logger",
11-
version="2.0.7",
11+
version="3.0.0.dev1",
1212
url="http://github.com/madzak/python-json-logger",
1313
license="BSD",
1414
include_package_data=True,
@@ -21,7 +21,7 @@
2121
package_data={"pythonjsonlogger": ["py.typed"]},
2222
packages=find_packages("src", exclude="tests"),
2323
# https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires
24-
python_requires=">=3.6",
24+
python_requires=">=3.7",
2525
test_suite="tests.tests",
2626
classifiers=[
2727
'Development Status :: 6 - Mature',
@@ -30,12 +30,13 @@
3030
'Operating System :: OS Independent',
3131
'Programming Language :: Python',
3232
'Programming Language :: Python :: 3',
33-
'Programming Language :: Python :: 3.6',
33+
'Programming Language :: Python :: 3 :: Only',
3434
'Programming Language :: Python :: 3.7',
3535
'Programming Language :: Python :: 3.8',
3636
'Programming Language :: Python :: 3.9',
3737
'Programming Language :: Python :: 3.10',
3838
'Programming Language :: Python :: 3.11',
39+
'Programming Language :: Python :: 3.12',
3940
'Topic :: System :: Logging',
4041
]
4142
)

src/pythonjsonlogger/jsonlogger.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
This library is provided to allow standard python logging
33
to output log data as JSON formatted strings
44
"""
5+
56
import logging
67
import json
78
import re
89
import traceback
910
import importlib
1011
from datetime import date, datetime, time, timezone
12+
import sys
1113
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
1214

1315
from inspect import istraceback
@@ -16,7 +18,8 @@
1618

1719
# skip natural LogRecord attributes
1820
# http://docs.python.org/library/logging.html#logrecord-attributes
19-
RESERVED_ATTRS: Tuple[str, ...] = (
21+
# Changed in 3.0.0, is now list[str] instead of tuple[str, ...]
22+
RESERVED_ATTRS: List[str] = [
2023
"args",
2124
"asctime",
2225
"created",
@@ -39,7 +42,11 @@
3942
"stack_info",
4043
"thread",
4144
"threadName",
42-
)
45+
]
46+
47+
if sys.version_info >= (3, 12):
48+
# taskName added in python 3.12
49+
RESERVED_ATTRS.append("taskName")
4350

4451
OptionalCallableOrStr = Optional[Union[Callable, str]]
4552

@@ -63,9 +70,7 @@ def merge_record_extra(
6370
rename_fields = {}
6471
for key, value in record.__dict__.items():
6572
# this allows to have numeric keys
66-
if key not in reserved and not (
67-
hasattr(key, "startswith") and key.startswith("_")
68-
):
73+
if key not in reserved and not (hasattr(key, "startswith") and key.startswith("_")):
6974
target[rename_fields.get(key, key)] = value
7075
return target
7176

@@ -79,10 +84,10 @@ def default(self, obj):
7984
if isinstance(obj, (date, datetime, time)):
8085
return self.format_datetime_obj(obj)
8186

82-
elif istraceback(obj):
87+
if istraceback(obj):
8388
return "".join(traceback.format_tb(obj)).strip()
8489

85-
elif type(obj) == Exception or isinstance(obj, Exception) or type(obj) == type:
90+
if type(obj) == Exception or isinstance(obj, Exception) or type(obj) == type:
8691
return str(obj)
8792

8893
try:
@@ -117,9 +122,9 @@ def __init__(
117122
prefix: str = "",
118123
rename_fields: Optional[dict] = None,
119124
static_fields: Optional[dict] = None,
120-
reserved_attrs: Tuple[str, ...] = RESERVED_ATTRS,
125+
reserved_attrs: Union[Tuple[str, ...], List[str]] = RESERVED_ATTRS,
121126
timestamp: Union[bool, str] = False,
122-
**kwargs: Any
127+
**kwargs: Any,
123128
):
124129
"""
125130
:param json_default: a function for encoding non-standard objects
@@ -197,8 +202,7 @@ def parse(self) -> List[str]:
197202

198203
if self._fmt:
199204
return formatter_style_pattern.findall(self._fmt)
200-
else:
201-
return []
205+
return []
202206

203207
def add_fields(
204208
self,

tox.ini

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
[tox]
22
requires = tox>=3
3-
envlist = lint, type, pypy{38,39}, py{36,37,38,39,310,311}
3+
envlist = lint, type, pypy{37,38,39,310}, py{37,38,39,310,311,312}
44

55
[gh-actions]
66
python =
7+
pypy-3.7: pypy37
78
pypy-3.8: pypy38
89
pypy-3.9: pypy39
9-
3.6: py36
10+
pypy-3.10: pypy310
1011
3.7: py37
1112
3.8: py38
1213
3.9: py39
1314
3.10: py310
14-
3.11: py311, type
15+
3.11: py311
16+
3.12: py312, type
1517

1618
[testenv]
1719
description = run unit tests

0 commit comments

Comments
 (0)