Commit 49f69fb
authored
Split core functionality and support orjson and msgspec (#9)
## Summary of changes
### Refactor common functionality into base module
This allows support multiple JSON encoders by having common
functionality in `pythonjsonlogger.core` and then specialist formatters
for each encoder.
This is useful / needed, as not all JSON encoders support the
`json.dumps` or `json.JSONEncoder` interfaces exactly. This enables us
to support other JSON encoders like orjson and msgspec. In the future we
may add support for other encoders.
### Better handling for custom styles
Achieved by mimicking `logging.Formatter.__init__` without actually
calling it.
A code snippet is worth `2**10` words:
```python
from pythonjsonlogger.core import BaseJsonLogger
class CommaSupport(BaseJsonFormatter):
def parse(self) -> list[str]:
if isinstance(self._style, str) and self._style == ",":
return self._fmt.split(",")
return super().parse()
f = CommaSupport("message,asctime", style=",", validate=False)
```
### Rename `jsonlogger` module to `json` module
Compatibility is maintained for the moment using `__getattr__` in
`__init__`.
This is to enable more consistent naming of implementation specific
module names. It also stops throwing around the word "logger" when this
module only contains formatters.
### Add support for orjson
[orjson](https://github.com/ijl/orjson) is a high performance (and more
JSON spec correct) encoder. Given how many logging calls may occur -
having a performant formatter available is important.
This includes ensuring it is covered in tests on appropriate platforms.
Note: orjson is not supported on pypy, and currently does not build for
py313.
### Add support for msgspec
[msgspec](https://jcristharif.com/msgspec/index.html) is another library
containing a high performance JSON encoder.
Note: msgspec is not supported on pypy, and currently does not build for
py313.
### Drops python 3.7 support
This is primary due do making use of the
[`validate`](https://docs.python.org/3/library/logging.html#formatter-objects)
argument. I was also having issues with CI because python 3.7 is not support on most "latest"1 parent 2767589 commit 49f69fb
File tree
15 files changed
+1126
-659
lines changed- .github/workflows
- src/pythonjsonlogger
- tests
15 files changed
+1126
-659
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
7 | 34 | | |
8 | 35 | | |
9 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | | - | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 79 | + | |
88 | 80 | | |
89 | 81 | | |
90 | 82 | | |
| |||
94 | 86 | | |
95 | 87 | | |
96 | 88 | | |
97 | | - | |
| 89 | + | |
98 | 90 | | |
99 | | - | |
| 91 | + | |
100 | 92 | | |
101 | 93 | | |
102 | 94 | | |
| |||
105 | 97 | | |
106 | 98 | | |
107 | 99 | | |
| 100 | + | |
108 | 101 | | |
109 | 102 | | |
110 | 103 | | |
111 | 104 | | |
112 | 105 | | |
113 | 106 | | |
114 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
115 | 135 | | |
116 | 136 | | |
117 | 137 | | |
118 | 138 | | |
119 | | - | |
| 139 | + | |
120 | 140 | | |
121 | 141 | | |
122 | 142 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 143 | + | |
129 | 144 | | |
130 | 145 | | |
131 | 146 | | |
132 | 147 | | |
133 | | - | |
| 148 | + | |
134 | 149 | | |
135 | 150 | | |
136 | 151 | | |
| |||
161 | 176 | | |
162 | 177 | | |
163 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
164 | 186 | | |
165 | 187 | | |
166 | 188 | | |
| |||
180 | 202 | | |
181 | 203 | | |
182 | 204 | | |
183 | | - | |
| 205 | + | |
184 | 206 | | |
185 | 207 | | |
186 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
29 | | - | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 55 | + | |
52 | 56 | | |
| 57 | + | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments