python-json-logger 3.2.1.dev1__tar.gz → 3.3.0__tar.gz

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.
Files changed (26) hide show
  1. {python_json_logger-3.2.1.dev1/src/python_json_logger.egg-info → python_json_logger-3.3.0}/PKG-INFO +4 -4
  2. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/README.md +1 -0
  3. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/pyproject.toml +2 -3
  4. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0/src/python_json_logger.egg-info}/PKG-INFO +4 -4
  5. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/python_json_logger.egg-info/requires.txt +0 -5
  6. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/core.py +24 -0
  7. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/tests/test_deprecation.py +17 -0
  8. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/tests/test_formatters.py +57 -2
  9. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/LICENSE +0 -0
  10. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/MANIFEST.in +0 -0
  11. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/NOTICE +0 -0
  12. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/setup.cfg +0 -0
  13. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/python_json_logger.egg-info/SOURCES.txt +0 -0
  14. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/python_json_logger.egg-info/dependency_links.txt +0 -0
  15. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/python_json_logger.egg-info/top_level.txt +0 -0
  16. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/__init__.py +0 -0
  17. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/defaults.py +0 -0
  18. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/exception.py +0 -0
  19. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/json.py +0 -0
  20. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/jsonlogger.py +0 -0
  21. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/msgspec.py +0 -0
  22. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/orjson.py +0 -0
  23. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/py.typed +0 -0
  24. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/src/pythonjsonlogger/utils.py +0 -0
  25. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/tests/__init__.py +0 -0
  26. {python_json_logger-3.2.1.dev1 → python_json_logger-3.3.0}/tests/test_missing.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: python-json-logger
3
- Version: 3.2.1.dev1
3
+ Version: 3.3.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>
@@ -27,8 +27,7 @@ License-File: NOTICE
27
27
  Requires-Dist: typing_extensions; python_version < "3.10"
28
28
  Provides-Extra: dev
29
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"
30
+ Requires-Dist: msgspec; implementation_name != "pypy" and extra == "dev"
32
31
  Requires-Dist: validate-pyproject[all]; extra == "dev"
33
32
  Requires-Dist: black; extra == "dev"
34
33
  Requires-Dist: pylint; extra == "dev"
@@ -49,6 +48,7 @@ Requires-Dist: mike; extra == "dev"
49
48
 
50
49
  [![PyPi](https://img.shields.io/pypi/v/python-json-logger.svg)](https://pypi.python.org/pypi/python-json-logger/)
51
50
  [![PyPI - Status](https://img.shields.io/pypi/status/python-json-logger)](https://pypi.python.org/pypi/python-json-logger/)
51
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/python-json-logger)](https://pypi.python.org/pypi/python-json-logger/)
52
52
  [![Python Versions](https://img.shields.io/pypi/pyversions/python-json-logger.svg)](https://github.com/nhairs/python-json-logger)
53
53
  [![License](https://img.shields.io/github/license/nhairs/python-json-logger.svg)](https://github.com/nhairs/python-json-logger)
54
54
  ![Build Status](https://github.com/nhairs/python-json-logger/actions/workflows/test-suite.yml/badge.svg)
@@ -1,5 +1,6 @@
1
1
  [![PyPi](https://img.shields.io/pypi/v/python-json-logger.svg)](https://pypi.python.org/pypi/python-json-logger/)
2
2
  [![PyPI - Status](https://img.shields.io/pypi/status/python-json-logger)](https://pypi.python.org/pypi/python-json-logger/)
3
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/python-json-logger)](https://pypi.python.org/pypi/python-json-logger/)
3
4
  [![Python Versions](https://img.shields.io/pypi/pyversions/python-json-logger.svg)](https://github.com/nhairs/python-json-logger)
4
5
  [![License](https://img.shields.io/github/license/nhairs/python-json-logger.svg)](https://github.com/nhairs/python-json-logger)
5
6
  ![Build Status](https://github.com/nhairs/python-json-logger/actions/workflows/test-suite.yml/badge.svg)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-json-logger"
7
- version = "3.2.1.dev1"
7
+ version = "3.3.0"
8
8
  description = "JSON Log Formatter for the Python Logging Package"
9
9
  authors = [
10
10
  {name = "Zakaria Zajac", email = "zak@madzak.com"},
@@ -47,8 +47,7 @@ GitHub = "https://github.com/nhairs/python-json-logger"
47
47
  dev = [
48
48
  ## Optional but required for dev
49
49
  "orjson;implementation_name!='pypy'",
50
- "msgspec;implementation_name!='pypy' and python_version<'3.13'",
51
- "msgspec-python313-pre;implementation_name!='pypy' and python_version=='3.13'",
50
+ "msgspec;implementation_name!='pypy'",
52
51
  ## Lint
53
52
  "validate-pyproject[all]",
54
53
  "black",
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: python-json-logger
3
- Version: 3.2.1.dev1
3
+ Version: 3.3.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>
@@ -27,8 +27,7 @@ License-File: NOTICE
27
27
  Requires-Dist: typing_extensions; python_version < "3.10"
28
28
  Provides-Extra: dev
29
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"
30
+ Requires-Dist: msgspec; implementation_name != "pypy" and extra == "dev"
32
31
  Requires-Dist: validate-pyproject[all]; extra == "dev"
33
32
  Requires-Dist: black; extra == "dev"
34
33
  Requires-Dist: pylint; extra == "dev"
@@ -49,6 +48,7 @@ Requires-Dist: mike; extra == "dev"
49
48
 
50
49
  [![PyPi](https://img.shields.io/pypi/v/python-json-logger.svg)](https://pypi.python.org/pypi/python-json-logger/)
51
50
  [![PyPI - Status](https://img.shields.io/pypi/status/python-json-logger)](https://pypi.python.org/pypi/python-json-logger/)
51
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/python-json-logger)](https://pypi.python.org/pypi/python-json-logger/)
52
52
  [![Python Versions](https://img.shields.io/pypi/pyversions/python-json-logger.svg)](https://github.com/nhairs/python-json-logger)
53
53
  [![License](https://img.shields.io/github/license/nhairs/python-json-logger.svg)](https://github.com/nhairs/python-json-logger)
54
54
  ![Build Status](https://github.com/nhairs/python-json-logger/actions/workflows/test-suite.yml/badge.svg)
@@ -22,12 +22,7 @@ mike
22
22
 
23
23
  [dev:implementation_name != "pypy"]
24
24
  orjson
25
-
26
- [dev:implementation_name != "pypy" and python_version < "3.13"]
27
25
  msgspec
28
26
 
29
- [dev:implementation_name != "pypy" and python_version == "3.13"]
30
- msgspec-python313-pre
31
-
32
27
  [dev:python_version < "3.9"]
33
28
  backports.zoneinfo
@@ -134,6 +134,8 @@ class BaseJsonFormatter(logging.Formatter):
134
134
  *New in 3.1*
135
135
 
136
136
  *Changed in 3.2*: `defaults` argument is no longer ignored.
137
+
138
+ *Added in UNRELEASED*: `exc_info_as_array` and `stack_info_as_array` options are added.
137
139
  """
138
140
 
139
141
  _style: Union[logging.PercentStyle, str] # type: ignore[assignment]
@@ -155,6 +157,8 @@ class BaseJsonFormatter(logging.Formatter):
155
157
  reserved_attrs: Optional[Sequence[str]] = None,
156
158
  timestamp: Union[bool, str] = False,
157
159
  defaults: Optional[Dict[str, Any]] = None,
160
+ exc_info_as_array: bool = False,
161
+ stack_info_as_array: bool = False,
158
162
  ) -> None:
159
163
  """
160
164
  Args:
@@ -177,6 +181,8 @@ class BaseJsonFormatter(logging.Formatter):
177
181
  outputting the json log record. If string is passed, timestamp will be added
178
182
  to log record using string as key. If True boolean is passed, timestamp key
179
183
  will be "timestamp". Defaults to False/off.
184
+ exc_info_as_array: break the exc_info into a list of lines based on line breaks.
185
+ stack_info_as_array: break the stack_info into a list of lines based on line breaks.
180
186
 
181
187
  *Changed in 3.1*:
182
188
 
@@ -219,6 +225,8 @@ class BaseJsonFormatter(logging.Formatter):
219
225
  self._skip_fields = set(self._required_fields)
220
226
  self._skip_fields.update(self.reserved_attrs)
221
227
  self.defaults = defaults if defaults is not None else {}
228
+ self.exc_info_as_array = exc_info_as_array
229
+ self.stack_info_as_array = stack_info_as_array
222
230
  return
223
231
 
224
232
  def format(self, record: logging.LogRecord) -> str:
@@ -368,3 +376,19 @@ class BaseJsonFormatter(logging.Formatter):
368
376
  log_record: incoming data
369
377
  """
370
378
  return log_record
379
+
380
+ def formatException(self, ei) -> Union[str, list[str]]: # type: ignore
381
+ """Format and return the specified exception information.
382
+
383
+ If exc_info_as_array is set to True, This method returns an array of strings.
384
+ """
385
+ exception_info_str = super().formatException(ei)
386
+ return exception_info_str.splitlines() if self.exc_info_as_array else exception_info_str
387
+
388
+ def formatStack(self, stack_info) -> Union[str, list[str]]: # type: ignore
389
+ """Format and return the specified stack information.
390
+
391
+ If stack_info_as_array is set to True, This method returns an array of strings.
392
+ """
393
+ stack_info_str = super().formatStack(stack_info)
394
+ return stack_info_str.splitlines() if self.stack_info_as_array else stack_info_str
@@ -4,6 +4,8 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  ## Standard Library
7
+ import subprocess
8
+ import sys
7
9
 
8
10
  ## Installed
9
11
  import pytest
@@ -26,3 +28,18 @@ def test_jsonlogger_reserved_attrs_deprecated():
26
28
  # a DeprecationWarning and we specifically want the one for RESERVED_ATTRS
27
29
  pythonjsonlogger.json.RESERVED_ATTRS
28
30
  return
31
+
32
+
33
+ @pytest.mark.parametrize(
34
+ "command",
35
+ [
36
+ "from pythonjsonlogger import jsonlogger",
37
+ "import pythonjsonlogger.jsonlogger",
38
+ "from pythonjsonlogger.jsonlogger import JsonFormatter",
39
+ "from pythonjsonlogger.jsonlogger import RESERVED_ATTRS",
40
+ ],
41
+ )
42
+ def test_import(command: str):
43
+ output = subprocess.check_output([sys.executable, "-c", f"{command};print('OK')"])
44
+ assert output.strip() == b"OK"
45
+ return
@@ -568,8 +568,14 @@ def test_common_types_encoded(
568
568
  if pythonjsonlogger.MSGSPEC_AVAILABLE and class_ is MsgspecFormatter:
569
569
  # Dataclass: https://github.com/jcrist/msgspec/issues/681
570
570
  # Enum: https://github.com/jcrist/msgspec/issues/680
571
- if obj is SomeDataclass or (
572
- isinstance(obj, enum.Enum) and obj in {MultiEnum.BYTES, MultiEnum.NONE, MultiEnum.BOOL}
571
+ # These have been fixed in msgspec 0.19.0, however they also dropped python 3.8 support.
572
+ # https://github.com/jcrist/msgspec/releases/tag/0.19.0
573
+ if sys.version_info < (3, 9) and (
574
+ obj is SomeDataclass
575
+ or (
576
+ isinstance(obj, enum.Enum)
577
+ and obj in {MultiEnum.BYTES, MultiEnum.NONE, MultiEnum.BOOL}
578
+ )
573
579
  ):
574
580
  pytest.xfail()
575
581
 
@@ -616,6 +622,55 @@ def test_custom_default(env: LoggingEnvironment, class_: type[BaseJsonFormatter]
616
622
  return
617
623
 
618
624
 
625
+ @pytest.mark.parametrize("class_", ALL_FORMATTERS)
626
+ def test_exc_info_as_array(env: LoggingEnvironment, class_: type[BaseJsonFormatter]):
627
+ env.set_formatter(class_(exc_info_as_array=True))
628
+
629
+ try:
630
+ raise Exception("Error")
631
+ except BaseException:
632
+ env.logger.exception("Error occurs")
633
+ log_json = env.load_json()
634
+
635
+ assert isinstance(log_json["exc_info"], list)
636
+ return
637
+
638
+
639
+ @pytest.mark.parametrize("class_", ALL_FORMATTERS)
640
+ def test_exc_info_as_array_no_exc_info(env: LoggingEnvironment, class_: type[BaseJsonFormatter]):
641
+ env.set_formatter(class_(exc_info_as_array=True))
642
+
643
+ env.logger.info("hello")
644
+ log_json = env.load_json()
645
+
646
+ assert "exc_info" not in log_json
647
+ return
648
+
649
+
650
+ @pytest.mark.parametrize("class_", ALL_FORMATTERS)
651
+ def test_stack_info_as_array(env: LoggingEnvironment, class_: type[BaseJsonFormatter]):
652
+ env.set_formatter(class_(stack_info_as_array=True))
653
+
654
+ env.logger.info("hello", stack_info=True)
655
+ log_json = env.load_json()
656
+
657
+ assert isinstance(log_json["stack_info"], list)
658
+ return
659
+
660
+
661
+ @pytest.mark.parametrize("class_", ALL_FORMATTERS)
662
+ def test_stack_info_as_array_no_stack_info(
663
+ env: LoggingEnvironment, class_: type[BaseJsonFormatter]
664
+ ):
665
+ env.set_formatter(class_(stack_info_as_array=True))
666
+
667
+ env.logger.info("hello", stack_info=False)
668
+ log_json = env.load_json()
669
+
670
+ assert "stack_info" not in log_json
671
+ return
672
+
673
+
619
674
  ## JsonFormatter Specific
620
675
  ## -----------------------------------------------------------------------------
621
676
  def test_json_ensure_ascii_true(env: LoggingEnvironment):