python-json-logger 3.1.0__py3-none-any.whl → 3.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_json_logger-3.1.0.dist-info → python_json_logger-3.2.0.dist-info}/METADATA +24 -22
- python_json_logger-3.2.0.dist-info/RECORD +15 -0
- {python_json_logger-3.1.0.dist-info → python_json_logger-3.2.0.dist-info}/WHEEL +1 -1
- pythonjsonlogger/__init__.py +3 -14
- pythonjsonlogger/core.py +11 -4
- pythonjsonlogger/exception.py +27 -0
- pythonjsonlogger/msgspec.py +5 -1
- pythonjsonlogger/orjson.py +6 -2
- pythonjsonlogger/utils.py +40 -0
- python_json_logger-3.1.0.dist-info/RECORD +0 -13
- {python_json_logger-3.1.0.dist-info → python_json_logger-3.2.0.dist-info}/LICENSE +0 -0
- {python_json_logger-3.1.0.dist-info → python_json_logger-3.2.0.dist-info}/NOTICE +0 -0
- {python_json_logger-3.1.0.dist-info → python_json_logger-3.2.0.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-json-logger
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: JSON Log Formatter for the Python Logging Package
|
|
5
5
|
Author-email: Zakaria Zajac <zak@madzak.com>, Nicholas Hairs <info+python-json-logger@nicholashairs.com>
|
|
6
6
|
Maintainer-email: Nicholas Hairs <info+python-json-logger@nicholashairs.com>
|
|
7
7
|
License: BSD-2-Clause License
|
|
8
|
-
Project-URL: Homepage, https://nhairs.github.io/python-json-logger
|
|
8
|
+
Project-URL: Homepage, https://nhairs.github.io/python-json-logger
|
|
9
9
|
Project-URL: GitHub, https://github.com/nhairs/python-json-logger
|
|
10
10
|
Classifier: Development Status :: 6 - Mature
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
@@ -17,33 +17,35 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
21
|
Classifier: Topic :: System :: Logging
|
|
21
22
|
Classifier: Typing :: Typed
|
|
22
23
|
Requires-Python: >=3.8
|
|
23
24
|
Description-Content-Type: text/markdown
|
|
24
25
|
License-File: LICENSE
|
|
25
26
|
License-File: NOTICE
|
|
26
|
-
Requires-Dist:
|
|
27
|
+
Requires-Dist: typing_extensions; python_version < "3.10"
|
|
27
28
|
Provides-Extra: dev
|
|
28
|
-
Requires-Dist:
|
|
29
|
-
Requires-Dist:
|
|
30
|
-
Requires-Dist:
|
|
31
|
-
Requires-Dist:
|
|
32
|
-
Requires-Dist:
|
|
33
|
-
Requires-Dist:
|
|
34
|
-
Requires-Dist:
|
|
35
|
-
Requires-Dist:
|
|
36
|
-
Requires-Dist:
|
|
37
|
-
Requires-Dist:
|
|
38
|
-
Requires-Dist:
|
|
39
|
-
Requires-Dist:
|
|
40
|
-
Requires-Dist:
|
|
41
|
-
Requires-Dist: mkdocs-
|
|
42
|
-
Requires-Dist: mkdocs-
|
|
43
|
-
Requires-Dist:
|
|
44
|
-
Requires-Dist:
|
|
45
|
-
Requires-Dist:
|
|
46
|
-
Requires-Dist:
|
|
29
|
+
Requires-Dist: orjson; implementation_name != "pypy" and extra == "dev"
|
|
30
|
+
Requires-Dist: msgspec; (implementation_name != "pypy" and python_version < "3.13") and extra == "dev"
|
|
31
|
+
Requires-Dist: msgspec-python313-pre; (implementation_name != "pypy" and python_version == "3.13") and extra == "dev"
|
|
32
|
+
Requires-Dist: validate-pyproject[all]; extra == "dev"
|
|
33
|
+
Requires-Dist: black; extra == "dev"
|
|
34
|
+
Requires-Dist: pylint; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest; extra == "dev"
|
|
37
|
+
Requires-Dist: freezegun; extra == "dev"
|
|
38
|
+
Requires-Dist: backports.zoneinfo; python_version < "3.9" and extra == "dev"
|
|
39
|
+
Requires-Dist: tzdata; extra == "dev"
|
|
40
|
+
Requires-Dist: build; extra == "dev"
|
|
41
|
+
Requires-Dist: mkdocs; extra == "dev"
|
|
42
|
+
Requires-Dist: mkdocs-material>=8.5; extra == "dev"
|
|
43
|
+
Requires-Dist: mkdocs-awesome-pages-plugin; extra == "dev"
|
|
44
|
+
Requires-Dist: mdx_truly_sane_lists; extra == "dev"
|
|
45
|
+
Requires-Dist: mkdocstrings[python]; extra == "dev"
|
|
46
|
+
Requires-Dist: mkdocs-gen-files; extra == "dev"
|
|
47
|
+
Requires-Dist: mkdocs-literate-nav; extra == "dev"
|
|
48
|
+
Requires-Dist: mike; extra == "dev"
|
|
47
49
|
|
|
48
50
|
<!-- [](https://pypi.python.org/pypi/python-json-logger/)
|
|
49
51
|
[](https://pypi.python.org/pypi/python-json-logger/)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
pythonjsonlogger/__init__.py,sha256=mvnVMTGrh32otHxVE7-MsxT9kBvmMyS6I3NCQDe55LY,898
|
|
2
|
+
pythonjsonlogger/core.py,sha256=zrf2vBMPVjPv5ornwWs2TOi68FbWDnuhj_DrcUiuBG0,13328
|
|
3
|
+
pythonjsonlogger/defaults.py,sha256=-XgxIj8ioq7CsnBBMsQhTRpU-lKbLrpQLJTCaT3iH38,6577
|
|
4
|
+
pythonjsonlogger/exception.py,sha256=r3DXDk7TThscnMVNPpVRaRSFHTnY-ygea6nn-FgjwsI,804
|
|
5
|
+
pythonjsonlogger/json.py,sha256=TsKD_1-TDjaeMUg6la_aVzIWd7GBxgAntY6zWzVe7lU,4165
|
|
6
|
+
pythonjsonlogger/msgspec.py,sha256=M5kiIX4RLr1PwvWKx21N8sgk05LCFymBAWM4cRR3VNA,2161
|
|
7
|
+
pythonjsonlogger/orjson.py,sha256=HVhIHo7CrTwj9pZuZzUmj1qsW0coNdVmDKSDycDs-pM,2357
|
|
8
|
+
pythonjsonlogger/py.typed,sha256=4RLptUHQuSqzK6CDbigff8uvWQjwPPQMxikWPkV4OtA,80
|
|
9
|
+
pythonjsonlogger/utils.py,sha256=qr04nb61TkVw7cJTXAtLBfyH_NBvyYUlR_mehH76-RM,1126
|
|
10
|
+
python_json_logger-3.2.0.dist-info/LICENSE,sha256=GOqVF546Xg4k62zhbED7--IxM8JQKTOi91-KPhoFW1Q,1329
|
|
11
|
+
python_json_logger-3.2.0.dist-info/METADATA,sha256=5eZGCDrb3mmrvVyiug9EYBtzaD_PDzZmHw_UUy4dlKc,4357
|
|
12
|
+
python_json_logger-3.2.0.dist-info/NOTICE,sha256=uRQnFcGZCwuIBR2AIHVvhKi9w1KkiI_vAyralfxCsk4,209
|
|
13
|
+
python_json_logger-3.2.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
14
|
+
python_json_logger-3.2.0.dist-info/top_level.txt,sha256=9G-OsTkbwPgM8t-bXKPmWDBRZv9cbzLIiEDE5EnGk2I,17
|
|
15
|
+
python_json_logger-3.2.0.dist-info/RECORD,,
|
pythonjsonlogger/__init__.py
CHANGED
|
@@ -9,23 +9,12 @@ import warnings
|
|
|
9
9
|
|
|
10
10
|
## Application
|
|
11
11
|
import pythonjsonlogger.json
|
|
12
|
+
import pythonjsonlogger.utils
|
|
12
13
|
|
|
13
14
|
### CONSTANTS
|
|
14
15
|
### ============================================================================
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
ORJSON_AVAILABLE = True
|
|
19
|
-
except ImportError:
|
|
20
|
-
ORJSON_AVAILABLE = False
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
try:
|
|
24
|
-
import msgspec
|
|
25
|
-
|
|
26
|
-
MSGSPEC_AVAILABLE = True
|
|
27
|
-
except ImportError:
|
|
28
|
-
MSGSPEC_AVAILABLE = False
|
|
16
|
+
ORJSON_AVAILABLE = pythonjsonlogger.utils.package_is_available("orjson")
|
|
17
|
+
MSGSPEC_AVAILABLE = pythonjsonlogger.utils.package_is_available("msgspec")
|
|
29
18
|
|
|
30
19
|
|
|
31
20
|
### DEPRECATED COMPATIBILITY
|
pythonjsonlogger/core.py
CHANGED
|
@@ -66,9 +66,9 @@ if sys.version_info >= (3, 12):
|
|
|
66
66
|
RESERVED_ATTRS.sort()
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
STYLE_STRING_TEMPLATE_REGEX = re.compile(r"\$\{(.+?)\}", re.IGNORECASE)
|
|
70
|
-
STYLE_STRING_FORMAT_REGEX = re.compile(r"\{(.+?)\}", re.IGNORECASE)
|
|
71
|
-
STYLE_PERCENT_REGEX = re.compile(r"%\((.+?)\)", re.IGNORECASE)
|
|
69
|
+
STYLE_STRING_TEMPLATE_REGEX = re.compile(r"\$\{(.+?)\}", re.IGNORECASE) # $ style
|
|
70
|
+
STYLE_STRING_FORMAT_REGEX = re.compile(r"\{(.+?)\}", re.IGNORECASE) # { style
|
|
71
|
+
STYLE_PERCENT_REGEX = re.compile(r"%\((.+?)\)", re.IGNORECASE) # % style
|
|
72
72
|
|
|
73
73
|
## Type Aliases
|
|
74
74
|
## -----------------------------------------------------------------------------
|
|
@@ -132,6 +132,8 @@ class BaseJsonFormatter(logging.Formatter):
|
|
|
132
132
|
Must not be used directly.
|
|
133
133
|
|
|
134
134
|
*New in 3.1*
|
|
135
|
+
|
|
136
|
+
*Changed in 3.2*: `defaults` argument is no longer ignored.
|
|
135
137
|
"""
|
|
136
138
|
|
|
137
139
|
_style: Union[logging.PercentStyle, str] # type: ignore[assignment]
|
|
@@ -161,7 +163,8 @@ class BaseJsonFormatter(logging.Formatter):
|
|
|
161
163
|
style: how to extract log fields from `fmt`
|
|
162
164
|
validate: validate `fmt` against style, if implementing a custom `style` you
|
|
163
165
|
must set this to `False`.
|
|
164
|
-
defaults:
|
|
166
|
+
defaults: a dictionary containing default fields that are added before all other fields and
|
|
167
|
+
may be overridden. The supplied fields are still subject to `rename_fields`.
|
|
165
168
|
prefix: an optional string prefix added at the beginning of
|
|
166
169
|
the formatted string
|
|
167
170
|
rename_fields: an optional dict, used to rename field names in the output.
|
|
@@ -215,6 +218,7 @@ class BaseJsonFormatter(logging.Formatter):
|
|
|
215
218
|
self._required_fields = self.parse()
|
|
216
219
|
self._skip_fields = set(self._required_fields)
|
|
217
220
|
self._skip_fields.update(self.reserved_attrs)
|
|
221
|
+
self.defaults = defaults if defaults is not None else {}
|
|
218
222
|
return
|
|
219
223
|
|
|
220
224
|
def format(self, record: logging.LogRecord) -> str:
|
|
@@ -310,6 +314,9 @@ class BaseJsonFormatter(logging.Formatter):
|
|
|
310
314
|
message_dict: dictionary that was logged instead of a message. e.g
|
|
311
315
|
`logger.info({"is_this_message_dict": True})`
|
|
312
316
|
"""
|
|
317
|
+
for field in self.defaults:
|
|
318
|
+
log_record[self._get_rename(field)] = self.defaults[field]
|
|
319
|
+
|
|
313
320
|
for field in self._required_fields:
|
|
314
321
|
log_record[self._get_rename(field)] = record.__dict__.get(field)
|
|
315
322
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
### IMPORTS
|
|
2
|
+
### ============================================================================
|
|
3
|
+
## Future
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
## Standard Library
|
|
7
|
+
|
|
8
|
+
## Installed
|
|
9
|
+
|
|
10
|
+
## Application
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### CLASSES
|
|
14
|
+
### ============================================================================
|
|
15
|
+
class PythonJsonLoggerError(Exception):
|
|
16
|
+
"Generic base clas for all Python JSON Logger exceptions"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class MissingPackageError(ImportError, PythonJsonLoggerError):
|
|
20
|
+
"A required package is missing"
|
|
21
|
+
|
|
22
|
+
def __init__(self, name: str, extras_name: str | None = None) -> None:
|
|
23
|
+
msg = f"The {name!r} package is required but could not be found."
|
|
24
|
+
if extras_name is not None:
|
|
25
|
+
msg += f" It can be installed using 'python-json-logger[{extras_name}]'."
|
|
26
|
+
super().__init__(msg)
|
|
27
|
+
return
|
pythonjsonlogger/msgspec.py
CHANGED
|
@@ -9,11 +9,15 @@ from __future__ import annotations
|
|
|
9
9
|
from typing import Any
|
|
10
10
|
|
|
11
11
|
## Installed
|
|
12
|
-
import msgspec.json
|
|
13
12
|
|
|
14
13
|
## Application
|
|
15
14
|
from . import core
|
|
16
15
|
from . import defaults as d
|
|
16
|
+
from .utils import package_is_available
|
|
17
|
+
|
|
18
|
+
# We import msgspec after checking it is available
|
|
19
|
+
package_is_available("msgspec", throw_error=True)
|
|
20
|
+
import msgspec.json # pylint: disable=wrong-import-position,wrong-import-order
|
|
17
21
|
|
|
18
22
|
|
|
19
23
|
### FUNCTIONS
|
pythonjsonlogger/orjson.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""JSON Formatter using [
|
|
1
|
+
"""JSON Formatter using [orjson](https://github.com/ijl/orjson)"""
|
|
2
2
|
|
|
3
3
|
### IMPORTS
|
|
4
4
|
### ============================================================================
|
|
@@ -9,11 +9,15 @@ from __future__ import annotations
|
|
|
9
9
|
from typing import Any
|
|
10
10
|
|
|
11
11
|
## Installed
|
|
12
|
-
import orjson
|
|
13
12
|
|
|
14
13
|
## Application
|
|
15
14
|
from . import core
|
|
16
15
|
from . import defaults as d
|
|
16
|
+
from .utils import package_is_available
|
|
17
|
+
|
|
18
|
+
# We import msgspec after checking it is available
|
|
19
|
+
package_is_available("orjson", throw_error=True)
|
|
20
|
+
import orjson # pylint: disable=wrong-import-position,wrong-import-order
|
|
17
21
|
|
|
18
22
|
|
|
19
23
|
### FUNCTIONS
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Utilities for Python JSON Logger"""
|
|
2
|
+
|
|
3
|
+
### IMPORTS
|
|
4
|
+
### ============================================================================
|
|
5
|
+
## Future
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
## Standard Library
|
|
9
|
+
import importlib.util
|
|
10
|
+
|
|
11
|
+
## Installed
|
|
12
|
+
|
|
13
|
+
## Application
|
|
14
|
+
from .exception import MissingPackageError
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### FUNCTIONS
|
|
18
|
+
### ============================================================================
|
|
19
|
+
def package_is_available(
|
|
20
|
+
name: str, *, throw_error: bool = False, extras_name: str | None = None
|
|
21
|
+
) -> bool:
|
|
22
|
+
"""Determine if the given package is available for import.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
name: Import name of the package to check.
|
|
26
|
+
throw_error: Throw an error if the package is unavailable.
|
|
27
|
+
extras_name: Extra dependency name to use in `throw_error`'s message.
|
|
28
|
+
|
|
29
|
+
Raises:
|
|
30
|
+
MissingPackageError: When `throw_error` is `True` and the return value would be `False`
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
If the package is available for import.
|
|
34
|
+
"""
|
|
35
|
+
available = importlib.util.find_spec(name) is not None
|
|
36
|
+
|
|
37
|
+
if not available and throw_error:
|
|
38
|
+
raise MissingPackageError(name, extras_name)
|
|
39
|
+
|
|
40
|
+
return available
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
pythonjsonlogger/__init__.py,sha256=J0u_TRg2RJcZFMapD5ZXUgCdiu57RmjdAy2JLMwD50s,927
|
|
2
|
-
pythonjsonlogger/core.py,sha256=A2SMUx_uYQ4vv1NI5tkk9cQyWXk9mpGOMJIq68SgJcI,12933
|
|
3
|
-
pythonjsonlogger/defaults.py,sha256=-XgxIj8ioq7CsnBBMsQhTRpU-lKbLrpQLJTCaT3iH38,6577
|
|
4
|
-
pythonjsonlogger/json.py,sha256=TsKD_1-TDjaeMUg6la_aVzIWd7GBxgAntY6zWzVe7lU,4165
|
|
5
|
-
pythonjsonlogger/msgspec.py,sha256=02ig_PtD9seLiO4HdaILIPezyVpPzik9L4kl1Cmq3VA,1959
|
|
6
|
-
pythonjsonlogger/orjson.py,sha256=9mlRh3Op8ZumIM5ippamhC9qqne9KmOKE6Y2SSORnHo,2157
|
|
7
|
-
pythonjsonlogger/py.typed,sha256=4RLptUHQuSqzK6CDbigff8uvWQjwPPQMxikWPkV4OtA,80
|
|
8
|
-
python_json_logger-3.1.0.dist-info/LICENSE,sha256=GOqVF546Xg4k62zhbED7--IxM8JQKTOi91-KPhoFW1Q,1329
|
|
9
|
-
python_json_logger-3.1.0.dist-info/METADATA,sha256=2cKiV8ZbtRiscpNXxxRR8Lj8xMBFAnzLE35HIcPBH60,4223
|
|
10
|
-
python_json_logger-3.1.0.dist-info/NOTICE,sha256=uRQnFcGZCwuIBR2AIHVvhKi9w1KkiI_vAyralfxCsk4,209
|
|
11
|
-
python_json_logger-3.1.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
12
|
-
python_json_logger-3.1.0.dist-info/top_level.txt,sha256=9G-OsTkbwPgM8t-bXKPmWDBRZv9cbzLIiEDE5EnGk2I,17
|
|
13
|
-
python_json_logger-3.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|