beans-logging 6.0.2__tar.gz → 7.0.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 (40) hide show
  1. {beans_logging-6.0.2/src/beans_logging.egg-info → beans_logging-7.0.0}/PKG-INFO +80 -61
  2. {beans_logging-6.0.2 → beans_logging-7.0.0}/README.md +71 -52
  3. {beans_logging-6.0.2 → beans_logging-7.0.0}/requirements/requirements.docs.txt +2 -2
  4. {beans_logging-6.0.2 → beans_logging-7.0.0}/requirements/requirements.test.txt +1 -1
  5. beans_logging-7.0.0/requirements.txt +3 -0
  6. {beans_logging-6.0.2 → beans_logging-7.0.0}/src/beans_logging/__init__.py +6 -6
  7. beans_logging-7.0.0/src/beans_logging/__version__.py +1 -0
  8. beans_logging-7.0.0/src/beans_logging/_builder.py +154 -0
  9. beans_logging-7.0.0/src/beans_logging/_constants.py +30 -0
  10. beans_logging-7.0.0/src/beans_logging/_core.py +295 -0
  11. beans_logging-7.0.0/src/beans_logging/_intercept.py +106 -0
  12. beans_logging-7.0.0/src/beans_logging/auto.py +15 -0
  13. beans_logging-7.0.0/src/beans_logging/config.py +186 -0
  14. {beans_logging-6.0.2 → beans_logging-7.0.0}/src/beans_logging/filters.py +37 -20
  15. {beans_logging-6.0.2 → beans_logging-7.0.0}/src/beans_logging/formats.py +20 -4
  16. beans_logging-6.0.2/src/beans_logging/rotation.py → beans_logging-7.0.0/src/beans_logging/rotators.py +20 -14
  17. beans_logging-7.0.0/src/beans_logging/schemas.py +143 -0
  18. {beans_logging-6.0.2 → beans_logging-7.0.0}/src/beans_logging/sinks.py +11 -2
  19. {beans_logging-6.0.2 → beans_logging-7.0.0/src/beans_logging.egg-info}/PKG-INFO +80 -61
  20. {beans_logging-6.0.2 → beans_logging-7.0.0}/src/beans_logging.egg-info/SOURCES.txt +6 -6
  21. {beans_logging-6.0.2 → beans_logging-7.0.0}/src/beans_logging.egg-info/requires.txt +8 -8
  22. beans_logging-6.0.2/auto.py +0 -6
  23. beans_logging-6.0.2/requirements.txt +0 -3
  24. beans_logging-6.0.2/src/beans_logging/__version__.py +0 -1
  25. beans_logging-6.0.2/src/beans_logging/_base.py +0 -660
  26. beans_logging-6.0.2/src/beans_logging/_consts.py +0 -18
  27. beans_logging-6.0.2/src/beans_logging/_handlers.py +0 -40
  28. beans_logging-6.0.2/src/beans_logging/_utils.py +0 -99
  29. beans_logging-6.0.2/src/beans_logging/auto.py +0 -24
  30. beans_logging-6.0.2/src/beans_logging/schemas.py +0 -173
  31. {beans_logging-6.0.2 → beans_logging-7.0.0}/.python-version +0 -0
  32. {beans_logging-6.0.2 → beans_logging-7.0.0}/LICENSE.txt +0 -0
  33. {beans_logging-6.0.2 → beans_logging-7.0.0}/pyproject.toml +0 -0
  34. {beans_logging-6.0.2 → beans_logging-7.0.0}/requirements/requirements.build.txt +0 -0
  35. {beans_logging-6.0.2 → beans_logging-7.0.0}/requirements/requirements.dev.txt +0 -0
  36. {beans_logging-6.0.2 → beans_logging-7.0.0}/requirements/requirements.fastapi.txt +0 -0
  37. {beans_logging-6.0.2 → beans_logging-7.0.0}/setup.cfg +0 -0
  38. {beans_logging-6.0.2 → beans_logging-7.0.0}/setup.py +0 -0
  39. {beans_logging-6.0.2 → beans_logging-7.0.0}/src/beans_logging.egg-info/dependency_links.txt +0 -0
  40. {beans_logging-6.0.2 → beans_logging-7.0.0}/src/beans_logging.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beans_logging
3
- Version: 6.0.2
3
+ Version: 7.0.0
4
4
  Summary: 'beans-logging' is a python package for simple logger and easily managing logs.
5
5
  Author-email: Batkhuu Byambajav <batkhuu10@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/bybatkhuu/module-python-logging
@@ -21,13 +21,13 @@ Classifier: Programming Language :: Python :: 3.13
21
21
  Requires-Python: <4.0,>=3.10
22
22
  Description-Content-Type: text/markdown
23
23
  License-File: LICENSE.txt
24
- Requires-Dist: PyYAML<7.0,>=6.0.2
25
- Requires-Dist: pydantic[timezone]!=2.1.0,<3.0.0,>=2.0.3
24
+ Requires-Dist: pydantic[timezone]<3.0.0,>=2.5.3
26
25
  Requires-Dist: loguru<1.0.0,>=0.7.3
26
+ Requires-Dist: potato_util<1.0.0,>=0.2.0
27
27
  Provides-Extra: fastapi
28
28
  Requires-Dist: beans-logging-fastapi<2.0.0,>=1.0.0; extra == "fastapi"
29
29
  Provides-Extra: test
30
- Requires-Dist: pytest<9.0.0,>=8.0.2; extra == "test"
30
+ Requires-Dist: pytest<10.0.0,>=8.0.2; extra == "test"
31
31
  Requires-Dist: pytest-cov<8.0.0,>=5.0.0; extra == "test"
32
32
  Requires-Dist: pytest-xdist<4.0.0,>=3.6.1; extra == "test"
33
33
  Requires-Dist: pytest-benchmark<6.0.0,>=5.0.1; extra == "test"
@@ -37,13 +37,13 @@ Requires-Dist: wheel<1.0.0,>=0.43.0; extra == "build"
37
37
  Requires-Dist: build<2.0.0,>=1.1.1; extra == "build"
38
38
  Requires-Dist: twine<7.0.0,>=6.0.1; extra == "build"
39
39
  Provides-Extra: docs
40
- Requires-Dist: pylint<4.0.0,>=3.0.4; extra == "docs"
40
+ Requires-Dist: pylint<5.0.0,>=3.0.4; extra == "docs"
41
41
  Requires-Dist: mkdocs-material<10.0.0,>=9.5.50; extra == "docs"
42
42
  Requires-Dist: mkdocs-awesome-nav<4.0.0,>=3.0.0; extra == "docs"
43
- Requires-Dist: mkdocstrings[python]<1.0.0,>=0.24.3; extra == "docs"
43
+ Requires-Dist: mkdocstrings[python]<2.0.0,>=0.24.3; extra == "docs"
44
44
  Requires-Dist: mike<3.0.0,>=2.1.3; extra == "docs"
45
45
  Provides-Extra: dev
46
- Requires-Dist: pytest<9.0.0,>=8.0.2; extra == "dev"
46
+ Requires-Dist: pytest<10.0.0,>=8.0.2; extra == "dev"
47
47
  Requires-Dist: pytest-cov<8.0.0,>=5.0.0; extra == "dev"
48
48
  Requires-Dist: pytest-xdist<4.0.0,>=3.6.1; extra == "dev"
49
49
  Requires-Dist: pytest-benchmark<6.0.0,>=5.0.1; extra == "dev"
@@ -51,10 +51,10 @@ Requires-Dist: setuptools<81.0.0,>=70.3.0; extra == "dev"
51
51
  Requires-Dist: wheel<1.0.0,>=0.43.0; extra == "dev"
52
52
  Requires-Dist: build<2.0.0,>=1.1.1; extra == "dev"
53
53
  Requires-Dist: twine<7.0.0,>=6.0.1; extra == "dev"
54
- Requires-Dist: pylint<4.0.0,>=3.0.4; extra == "dev"
54
+ Requires-Dist: pylint<5.0.0,>=3.0.4; extra == "dev"
55
55
  Requires-Dist: mkdocs-material<10.0.0,>=9.5.50; extra == "dev"
56
56
  Requires-Dist: mkdocs-awesome-nav<4.0.0,>=3.0.0; extra == "dev"
57
- Requires-Dist: mkdocstrings[python]<1.0.0,>=0.24.3; extra == "dev"
57
+ Requires-Dist: mkdocstrings[python]<2.0.0,>=0.24.3; extra == "dev"
58
58
  Requires-Dist: mike<3.0.0,>=2.1.3; extra == "dev"
59
59
  Requires-Dist: pyright<2.0.0,>=1.1.392; extra == "dev"
60
60
  Requires-Dist: pre-commit<5.0.0,>=4.0.1; extra == "dev"
@@ -217,12 +217,18 @@ logger.info("Logging info.")
217
217
 
218
218
  ```yml
219
219
  logger:
220
- app_name: "my-app"
221
- level: "TRACE"
222
- file:
223
- log_handlers:
220
+ app_name: my-app
221
+ default:
222
+ level:
223
+ base: TRACE
224
+ handlers:
225
+ default.all.file_handler:
224
226
  enabled: true
225
- json_handlers:
227
+ default.err.file_handler:
228
+ enabled: true
229
+ default.all.json_handler:
230
+ enabled: true
231
+ default.err.json_handler:
226
232
  enabled: true
227
233
  ```
228
234
 
@@ -273,28 +279,28 @@ python ./main.py
273
279
  **Output**:
274
280
 
275
281
  ```txt
276
- [2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:478]: Intercepted modules: ['concurrent', 'concurrent.futures', 'asyncio']; Muted modules: [];
277
- [2023-09-01 00:00:00.000 +09:00 | TRACE | __main__:7]: Tracing...
278
- [2023-09-01 00:00:00.000 +09:00 | DEBUG | __main__:8]: Debugging...
279
- [2023-09-01 00:00:00.000 +09:00 | INFO | __main__:9]: Logging info.
280
- [2023-09-01 00:00:00.000 +09:00 | OK | __main__:10]: Success.
281
- [2023-09-01 00:00:00.000 +09:00 | WARN | __main__:11]: Warning something.
282
- [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:12]: Error occured.
283
- [2023-09-01 00:00:00.000 +09:00 | CRIT | __main__:13]: CRITICAL ERROR.
284
- [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:25]: division by zero
285
- [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:32]: Show me, what value is wrong:
282
+ [2025-11-01 00:00:00.735 +09:00 | TRACE | beans_logging._intercept:96]: Intercepted modules: ['potato_util._base', 'potato_util.io', 'concurrent', 'concurrent.futures', 'asyncio', 'potato_util.io._sync', 'potato_util']; Muted modules: [];
283
+ [2025-11-01 00:00:00.736 +09:00 | TRACE | __main__:6]: Tracing...
284
+ [2025-11-01 00:00:00.736 +09:00 | DEBUG | __main__:7]: Debugging...
285
+ [2025-11-01 00:00:00.736 +09:00 | INFO | __main__:8]: Logging info.
286
+ [2025-11-01 00:00:00.736 +09:00 | OK | __main__:9]: Success.
287
+ [2025-11-01 00:00:00.736 +09:00 | WARN | __main__:10]: Warning something.
288
+ [2025-11-01 00:00:00.736 +09:00 | ERROR | __main__:11]: Error occured.
289
+ [2025-11-01 00:00:00.736 +09:00 | CRIT | __main__:12]: CRITICAL ERROR.
290
+ [2025-11-01 00:00:00.736 +09:00 | ERROR | __main__:24]: division by zero
291
+ [2025-11-01 00:00:00.737 +09:00 | ERROR | __main__:31]: Show me, what value is wrong:
286
292
  Traceback (most recent call last):
287
293
 
288
- > File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
294
+ > File "/home/user/workspaces/projects/my/module-python-logging/examples/simple/./main.py", line 29, in <module>
289
295
  nested(0)
290
- └ <function nested at 0x10802a4c0>
296
+ └ <function nested at 0x102f37910>
291
297
 
292
- File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 23, in nested
298
+ File "/home/user/workspaces/projects/my/module-python-logging/examples/simple/./main.py", line 22, in nested
293
299
  divide(5, c)
294
300
  │ └ 0
295
- └ <function divide at 0x1052f31f0>
301
+ └ <function divide at 0x102f377f0>
296
302
 
297
- File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 17, in divide
303
+ File "/home/user/workspaces/projects/my/module-python-logging/examples/simple/./main.py", line 16, in divide
298
304
  _result = a / b
299
305
  │ └ 0
300
306
  └ 5
@@ -312,37 +318,54 @@ ZeroDivisionError: division by zero
312
318
 
313
319
  ```yaml
314
320
  logger:
315
- # app_name: "app"
316
- level: "INFO"
317
- use_diagnose: false
318
- stream:
319
- use_color: true
320
- use_icon: false
321
- format_str: "[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{level_short:<5}</level> | <w>{name}:{line}</w>]: <level>{message}</level>"
322
- std_handler:
323
- enabled: true
324
- file:
325
- logs_dir: "./logs"
326
- rotate_size: 10000000 # 10MB
327
- rotate_time: "00:00:00"
328
- backup_count: 90
329
- log_handlers:
330
- enabled: false
331
- format_str: "[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {level_short:<5} | {name}:{line}]: {message}"
332
- log_path: "{app_name}.std.all.log"
333
- err_path: "{app_name}.std.err.log"
334
- json_handlers:
335
- enabled: false
336
- use_custom: false
337
- log_path: "{app_name}.json.all.log"
338
- err_path: "{app_name}.json.err.log"
321
+ # app_name: app
322
+ default:
323
+ level:
324
+ base: INFO
325
+ err: WARNING
326
+ std:
327
+ format_str: "[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{extra[level_short]:<5}</level> | <w>{name}:{line}</w>]: <level>{message}</level>"
328
+ colorize: true
329
+ format_str: "[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {extra[level_short]:<5} | {name}:{line}]: {message}"
330
+ file:
331
+ logs_dir: "./logs"
332
+ rotate_size: 10000000
333
+ rotate_time: "00:00:00"
334
+ retention: 90
335
+ encoding: utf8
336
+ plain:
337
+ log_path: "{app_name}.all.log"
338
+ err_path: "{app_name}.err.log"
339
+ json:
340
+ log_path: "json/{app_name}.json.all.log"
341
+ err_path: "json/{app_name}.json.err.log"
342
+ custom_serialize: false
339
343
  intercept:
340
- auto_load:
341
- enabled: true
342
- only_base: false
343
- ignore_modules: []
344
+ enabled: true
345
+ only_base: false
346
+ ignore_modules: []
344
347
  include_modules: []
345
348
  mute_modules: []
349
+ handlers:
350
+ default.all.std_handler:
351
+ type: STD
352
+ enabled: true
353
+ default.all.file_handler:
354
+ type: FILE
355
+ enabled: false
356
+ default.err.file_handler:
357
+ type: FILE
358
+ error: true
359
+ enabled: false
360
+ default.all.json_handler:
361
+ type: FILE
362
+ serialize: true
363
+ enabled: false
364
+ default.err.json_handler:
365
+ type: FILE
366
+ serialize: true
367
+ error: true
368
+ enabled: false
346
369
  extra:
347
370
  ```
348
371
 
@@ -354,10 +377,6 @@ logger:
354
377
  # ENV=LOCAL
355
378
  # DEBUG=false
356
379
  # TZ=UTC
357
-
358
- # BEANS_LOGGING_DISABLE_DEFAULT=false
359
- # BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml"
360
- # BEANS_LOGGING_LOGS_DIR="./logs"
361
380
  ```
362
381
 
363
382
  ---
@@ -155,12 +155,18 @@ logger.info("Logging info.")
155
155
 
156
156
  ```yml
157
157
  logger:
158
- app_name: "my-app"
159
- level: "TRACE"
160
- file:
161
- log_handlers:
158
+ app_name: my-app
159
+ default:
160
+ level:
161
+ base: TRACE
162
+ handlers:
163
+ default.all.file_handler:
162
164
  enabled: true
163
- json_handlers:
165
+ default.err.file_handler:
166
+ enabled: true
167
+ default.all.json_handler:
168
+ enabled: true
169
+ default.err.json_handler:
164
170
  enabled: true
165
171
  ```
166
172
 
@@ -211,28 +217,28 @@ python ./main.py
211
217
  **Output**:
212
218
 
213
219
  ```txt
214
- [2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:478]: Intercepted modules: ['concurrent', 'concurrent.futures', 'asyncio']; Muted modules: [];
215
- [2023-09-01 00:00:00.000 +09:00 | TRACE | __main__:7]: Tracing...
216
- [2023-09-01 00:00:00.000 +09:00 | DEBUG | __main__:8]: Debugging...
217
- [2023-09-01 00:00:00.000 +09:00 | INFO | __main__:9]: Logging info.
218
- [2023-09-01 00:00:00.000 +09:00 | OK | __main__:10]: Success.
219
- [2023-09-01 00:00:00.000 +09:00 | WARN | __main__:11]: Warning something.
220
- [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:12]: Error occured.
221
- [2023-09-01 00:00:00.000 +09:00 | CRIT | __main__:13]: CRITICAL ERROR.
222
- [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:25]: division by zero
223
- [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:32]: Show me, what value is wrong:
220
+ [2025-11-01 00:00:00.735 +09:00 | TRACE | beans_logging._intercept:96]: Intercepted modules: ['potato_util._base', 'potato_util.io', 'concurrent', 'concurrent.futures', 'asyncio', 'potato_util.io._sync', 'potato_util']; Muted modules: [];
221
+ [2025-11-01 00:00:00.736 +09:00 | TRACE | __main__:6]: Tracing...
222
+ [2025-11-01 00:00:00.736 +09:00 | DEBUG | __main__:7]: Debugging...
223
+ [2025-11-01 00:00:00.736 +09:00 | INFO | __main__:8]: Logging info.
224
+ [2025-11-01 00:00:00.736 +09:00 | OK | __main__:9]: Success.
225
+ [2025-11-01 00:00:00.736 +09:00 | WARN | __main__:10]: Warning something.
226
+ [2025-11-01 00:00:00.736 +09:00 | ERROR | __main__:11]: Error occured.
227
+ [2025-11-01 00:00:00.736 +09:00 | CRIT | __main__:12]: CRITICAL ERROR.
228
+ [2025-11-01 00:00:00.736 +09:00 | ERROR | __main__:24]: division by zero
229
+ [2025-11-01 00:00:00.737 +09:00 | ERROR | __main__:31]: Show me, what value is wrong:
224
230
  Traceback (most recent call last):
225
231
 
226
- > File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
232
+ > File "/home/user/workspaces/projects/my/module-python-logging/examples/simple/./main.py", line 29, in <module>
227
233
  nested(0)
228
- └ <function nested at 0x10802a4c0>
234
+ └ <function nested at 0x102f37910>
229
235
 
230
- File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 23, in nested
236
+ File "/home/user/workspaces/projects/my/module-python-logging/examples/simple/./main.py", line 22, in nested
231
237
  divide(5, c)
232
238
  │ └ 0
233
- └ <function divide at 0x1052f31f0>
239
+ └ <function divide at 0x102f377f0>
234
240
 
235
- File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 17, in divide
241
+ File "/home/user/workspaces/projects/my/module-python-logging/examples/simple/./main.py", line 16, in divide
236
242
  _result = a / b
237
243
  │ └ 0
238
244
  └ 5
@@ -250,37 +256,54 @@ ZeroDivisionError: division by zero
250
256
 
251
257
  ```yaml
252
258
  logger:
253
- # app_name: "app"
254
- level: "INFO"
255
- use_diagnose: false
256
- stream:
257
- use_color: true
258
- use_icon: false
259
- format_str: "[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{level_short:<5}</level> | <w>{name}:{line}</w>]: <level>{message}</level>"
260
- std_handler:
261
- enabled: true
262
- file:
263
- logs_dir: "./logs"
264
- rotate_size: 10000000 # 10MB
265
- rotate_time: "00:00:00"
266
- backup_count: 90
267
- log_handlers:
268
- enabled: false
269
- format_str: "[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {level_short:<5} | {name}:{line}]: {message}"
270
- log_path: "{app_name}.std.all.log"
271
- err_path: "{app_name}.std.err.log"
272
- json_handlers:
273
- enabled: false
274
- use_custom: false
275
- log_path: "{app_name}.json.all.log"
276
- err_path: "{app_name}.json.err.log"
259
+ # app_name: app
260
+ default:
261
+ level:
262
+ base: INFO
263
+ err: WARNING
264
+ std:
265
+ format_str: "[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{extra[level_short]:<5}</level> | <w>{name}:{line}</w>]: <level>{message}</level>"
266
+ colorize: true
267
+ format_str: "[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {extra[level_short]:<5} | {name}:{line}]: {message}"
268
+ file:
269
+ logs_dir: "./logs"
270
+ rotate_size: 10000000
271
+ rotate_time: "00:00:00"
272
+ retention: 90
273
+ encoding: utf8
274
+ plain:
275
+ log_path: "{app_name}.all.log"
276
+ err_path: "{app_name}.err.log"
277
+ json:
278
+ log_path: "json/{app_name}.json.all.log"
279
+ err_path: "json/{app_name}.json.err.log"
280
+ custom_serialize: false
277
281
  intercept:
278
- auto_load:
279
- enabled: true
280
- only_base: false
281
- ignore_modules: []
282
+ enabled: true
283
+ only_base: false
284
+ ignore_modules: []
282
285
  include_modules: []
283
286
  mute_modules: []
287
+ handlers:
288
+ default.all.std_handler:
289
+ type: STD
290
+ enabled: true
291
+ default.all.file_handler:
292
+ type: FILE
293
+ enabled: false
294
+ default.err.file_handler:
295
+ type: FILE
296
+ error: true
297
+ enabled: false
298
+ default.all.json_handler:
299
+ type: FILE
300
+ serialize: true
301
+ enabled: false
302
+ default.err.json_handler:
303
+ type: FILE
304
+ serialize: true
305
+ error: true
306
+ enabled: false
284
307
  extra:
285
308
  ```
286
309
 
@@ -292,10 +315,6 @@ logger:
292
315
  # ENV=LOCAL
293
316
  # DEBUG=false
294
317
  # TZ=UTC
295
-
296
- # BEANS_LOGGING_DISABLE_DEFAULT=false
297
- # BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml"
298
- # BEANS_LOGGING_LOGS_DIR="./logs"
299
318
  ```
300
319
 
301
320
  ---
@@ -1,5 +1,5 @@
1
- pylint>=3.0.4,<4.0.0
1
+ pylint>=3.0.4,<5.0.0
2
2
  mkdocs-material>=9.5.50,<10.0.0
3
3
  mkdocs-awesome-nav>=3.0.0,<4.0.0
4
- mkdocstrings[python]>=0.24.3,<1.0.0
4
+ mkdocstrings[python]>=0.24.3,<2.0.0
5
5
  mike>=2.1.3,<3.0.0
@@ -1,4 +1,4 @@
1
- pytest>=8.0.2,<9.0.0
1
+ pytest>=8.0.2,<10.0.0
2
2
  pytest-cov>=5.0.0,<8.0.0
3
3
  pytest-xdist>=3.6.1,<4.0.0
4
4
  pytest-benchmark>=5.0.1,<6.0.0
@@ -0,0 +1,3 @@
1
+ pydantic[timezone]>=2.5.3,<3.0.0
2
+ loguru>=0.7.3,<1.0.0
3
+ potato_util>=0.2.0,<1.0.0
@@ -1,14 +1,14 @@
1
- from ._base import Logger, logger, LoggerLoader
2
- from .schemas import LoggerConfigPM
3
- from ._consts import WarnEnum
1
+ from __future__ import annotations
2
+
4
3
  from .__version__ import __version__
4
+ from .config import LoggerConfigPM
5
+ from ._core import Logger, logger, LoggerLoader
5
6
 
6
7
 
7
8
  __all__ = [
9
+ "__version__",
10
+ "LoggerConfigPM",
8
11
  "Logger",
9
12
  "logger",
10
13
  "LoggerLoader",
11
- "LoggerConfigPM",
12
- "WarnEnum",
13
- "__version__",
14
14
  ]
@@ -0,0 +1 @@
1
+ __version__ = "7.0.0"
@@ -0,0 +1,154 @@
1
+ import os
2
+ from typing import Any
3
+
4
+ from pydantic import validate_call
5
+
6
+ from ._constants import LogHandlerTypeEnum, LogLevelEnum
7
+ from .schemas import LogHandlerPM
8
+ from .config import LoggerConfigPM
9
+ from .sinks import std_sink
10
+ from .formats import json_formatter
11
+ from .filters import (
12
+ use_all_filter,
13
+ use_std_filter,
14
+ use_file_filter,
15
+ use_file_err_filter,
16
+ use_file_json_filter,
17
+ use_file_json_err_filter,
18
+ )
19
+ from .rotators import Rotator
20
+
21
+
22
+ @validate_call
23
+ def build_handler(handler: LogHandlerPM, config: LoggerConfigPM) -> dict[str, Any]:
24
+ """Build handler config as dictionary for Loguru logger to add new handler.
25
+
26
+ Args:
27
+ handler (LogHandlerPM , required): Target log handler model.
28
+ config (LoggerConfigPM, required): Default main config model to fill missing values.
29
+
30
+ Raises:
31
+ ValueError: 'sink' attribute is empty, required for any log handler except std and file handlers!
32
+
33
+ Returns:
34
+ dict[str, Any]: Loguru handler config as dictionary.
35
+ """
36
+
37
+ _handler_dict = handler.model_dump(by_alias=True, exclude_none=True)
38
+
39
+ if _handler_dict.get("sink") is None:
40
+ if _handler_dict.get("type") == LogHandlerTypeEnum.STD:
41
+ _handler_dict["sink"] = std_sink
42
+ elif _handler_dict.get("type") == LogHandlerTypeEnum.FILE:
43
+ _logs_path: str = ""
44
+ if _handler_dict.get("serialize") or _handler_dict.get("custom_serialize"):
45
+ if _handler_dict.get("error"):
46
+ _logs_path = os.path.join(
47
+ config.default.file.logs_dir,
48
+ config.default.file.json_.err_path,
49
+ )
50
+ else:
51
+ _logs_path = os.path.join(
52
+ config.default.file.logs_dir,
53
+ config.default.file.json_.log_path,
54
+ )
55
+ else:
56
+ if _handler_dict.get("error"):
57
+ _logs_path = os.path.join(
58
+ config.default.file.logs_dir,
59
+ config.default.file.plain.err_path,
60
+ )
61
+ else:
62
+ _logs_path = os.path.join(
63
+ config.default.file.logs_dir,
64
+ config.default.file.plain.log_path,
65
+ )
66
+
67
+ if "{app_name}" in _logs_path:
68
+ _logs_path = _logs_path.format(app_name=config.app_name)
69
+
70
+ _handler_dict["sink"] = _logs_path
71
+ else:
72
+ raise ValueError(
73
+ "'sink' attribute is empty, required for any log handler except std and file handlers!"
74
+ )
75
+
76
+ if _handler_dict.get("level") is None:
77
+ if _handler_dict.get("error"):
78
+ _handler_dict["level"] = config.default.level.err
79
+ else:
80
+ _handler_dict["level"] = config.default.level.base
81
+
82
+ if (_handler_dict.get("custom_serialize") is None) and _handler_dict.get(
83
+ "serialize"
84
+ ):
85
+ _handler_dict["custom_serialize"] = config.default.custom_serialize
86
+
87
+ if _handler_dict.get("custom_serialize"):
88
+ _handler_dict["serialize"] = False
89
+ _handler_dict["format"] = json_formatter
90
+
91
+ if (_handler_dict.get("format") is None) and (not _handler_dict.get("serialize")):
92
+ if _handler_dict.get("type") == LogHandlerTypeEnum.STD:
93
+ _handler_dict["format"] = config.default.std.format_str
94
+ else:
95
+ _handler_dict["format"] = config.default.format_str
96
+
97
+ if _handler_dict.get("filter") is None:
98
+ if _handler_dict.get("type") == LogHandlerTypeEnum.STD:
99
+ _handler_dict["filter"] = use_std_filter
100
+ elif _handler_dict.get("type") == LogHandlerTypeEnum.FILE:
101
+ if _handler_dict.get("serialize") or _handler_dict.get("custom_serialize"):
102
+ if _handler_dict.get("error"):
103
+ _handler_dict["filter"] = use_file_json_err_filter
104
+ else:
105
+ _handler_dict["filter"] = use_file_json_filter
106
+ else:
107
+ if _handler_dict.get("error"):
108
+ _handler_dict["filter"] = use_file_err_filter
109
+ else:
110
+ _handler_dict["filter"] = use_file_filter
111
+ else:
112
+ _handler_dict["filter"] = use_all_filter
113
+
114
+ if _handler_dict.get("backtrace") is None:
115
+ _handler_dict["backtrace"] = True
116
+
117
+ if (_handler_dict.get("diagnose") is None) and (
118
+ (_handler_dict.get("level") == LogLevelEnum.TRACE)
119
+ or (_handler_dict.get("level") == 5)
120
+ ):
121
+ _handler_dict["diagnose"] = True
122
+
123
+ if (_handler_dict.get("colorize") is None) and (
124
+ _handler_dict.get("type") == LogHandlerTypeEnum.STD
125
+ ):
126
+ _handler_dict["colorize"] = config.default.std.colorize
127
+
128
+ if _handler_dict.get("type") == LogHandlerTypeEnum.FILE:
129
+ if _handler_dict.get("enqueue") is None:
130
+ _handler_dict["enqueue"] = True
131
+
132
+ if _handler_dict.get("rotation") is None:
133
+ _handler_dict["rotation"] = Rotator(
134
+ rotate_size=config.default.file.rotate_size,
135
+ rotate_time=config.default.file.rotate_time,
136
+ ).should_rotate
137
+
138
+ if _handler_dict.get("retention") is None:
139
+ _handler_dict["retention"] = config.default.file.retention
140
+
141
+ if _handler_dict.get("encoding") is None:
142
+ _handler_dict["encoding"] = config.default.file.encoding
143
+
144
+ _handler_dict.pop("type", None)
145
+ _handler_dict.pop("error", None)
146
+ _handler_dict.pop("custom_serialize", None)
147
+ _handler_dict.pop("enabled", None)
148
+
149
+ return _handler_dict
150
+
151
+
152
+ __all__ = [
153
+ "build_handler",
154
+ ]
@@ -0,0 +1,30 @@
1
+ from enum import Enum
2
+
3
+
4
+ class LogHandlerTypeEnum(str, Enum):
5
+ STD = "STD"
6
+ FILE = "FILE"
7
+ SOCKET = "SOCKET"
8
+ HTTP = "HTTP"
9
+ SYSLOG = "SYSLOG"
10
+ QUEUE = "QUEUE"
11
+ MEMORY = "MEMORY"
12
+ NULL = "NULL"
13
+ CUSTOM = "CUSTOM"
14
+ UNKNOWN = "UNKNOWN"
15
+
16
+
17
+ class LogLevelEnum(str, Enum):
18
+ TRACE = "TRACE"
19
+ DEBUG = "DEBUG"
20
+ INFO = "INFO"
21
+ SUCCESS = "SUCCESS"
22
+ WARNING = "WARNING"
23
+ ERROR = "ERROR"
24
+ CRITICAL = "CRITICAL"
25
+
26
+
27
+ __all__ = [
28
+ "LogHandlerTypeEnum",
29
+ "LogLevelEnum",
30
+ ]