beans-logging 4.3.1__tar.gz → 4.3.2__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.
- {beans_logging-4.3.1 → beans_logging-4.3.2}/PKG-INFO +29 -28
- {beans_logging-4.3.1 → beans_logging-4.3.2}/README.md +27 -26
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/__version__.py +1 -1
- beans_logging-4.3.1/beans_logging/schemas/config.py → beans_logging-4.3.2/beans_logging/schemas.py +71 -31
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging.egg-info/PKG-INFO +29 -28
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging.egg-info/SOURCES.txt +1 -3
- beans_logging-4.3.1/beans_logging/schemas/__init__.py +0 -8
- beans_logging-4.3.1/beans_logging/schemas/config_v1.py +0 -128
- {beans_logging-4.3.1 → beans_logging-4.3.2}/LICENSE.txt +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/__init__.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/_base.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/_consts.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/_handlers.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/_utils.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/auto.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/fastapi/__init__.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/fastapi/_filters.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/fastapi/_formats.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/fastapi/_handlers.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/fastapi/_middlewares.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/filters.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/formats.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/rotation.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging/sinks.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging.egg-info/dependency_links.txt +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging.egg-info/requires.txt +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/beans_logging.egg-info/top_level.txt +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/setup.cfg +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/setup.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/tests/__init__.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/tests/conftest.py +0 -0
- {beans_logging-4.3.1 → beans_logging-4.3.2}/tests/test_beans_logging.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: beans_logging
|
|
3
|
-
Version: 4.3.
|
|
3
|
+
Version: 4.3.2
|
|
4
4
|
Summary: 'beans_logging' is a python package for simple logger and easily managing logging modules. It is a Loguru based custom logging package for python projects.
|
|
5
5
|
Home-page: https://github.com/bybatkhuu/module.python-logging
|
|
6
|
-
Download-URL: https://github.com/bybatkhuu/module.python-logging/archive/v4.3.
|
|
6
|
+
Download-URL: https://github.com/bybatkhuu/module.python-logging/archive/v4.3.2.tar.gz
|
|
7
7
|
Author: Batkhuu Byambajav
|
|
8
8
|
Author-email: batkhuu10@gmail.com
|
|
9
9
|
License: MIT
|
|
@@ -49,6 +49,7 @@ It is a `Loguru` based custom logging package for python projects.
|
|
|
49
49
|
- Add custom **handlers**
|
|
50
50
|
- **FastAPI** HTTP access logging **middleware**
|
|
51
51
|
- **Base** logging module
|
|
52
|
+
- Support **Pydantic-v1** and **Pydantic-v2**
|
|
52
53
|
|
|
53
54
|
---
|
|
54
55
|
|
|
@@ -206,16 +207,16 @@ python ./main.py
|
|
|
206
207
|
**Output**:
|
|
207
208
|
|
|
208
209
|
```txt
|
|
209
|
-
[2023-09-01
|
|
210
|
-
[2023-09-01
|
|
211
|
-
[2023-09-01
|
|
212
|
-
[2023-09-01
|
|
213
|
-
[2023-09-01
|
|
214
|
-
[2023-09-01
|
|
215
|
-
[2023-09-01
|
|
216
|
-
[2023-09-01
|
|
217
|
-
[2023-09-01
|
|
218
|
-
[2023-09-01
|
|
210
|
+
[2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:478]: Intercepted modules: ['concurrent', 'concurrent.futures', 'asyncio']; Muted modules: [];
|
|
211
|
+
[2023-09-01 00:00:00.000 +09:00 | TRACE | __main__:7]: Tracing...
|
|
212
|
+
[2023-09-01 00:00:00.000 +09:00 | DEBUG | __main__:8]: Debugging...
|
|
213
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | __main__:9]: Logging info.
|
|
214
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | __main__:10]: Success.
|
|
215
|
+
[2023-09-01 00:00:00.000 +09:00 | WARN | __main__:11]: Warning something.
|
|
216
|
+
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:12]: Error occured.
|
|
217
|
+
[2023-09-01 00:00:00.000 +09:00 | CRIT | __main__:13]: CRITICAL ERROR.
|
|
218
|
+
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:25]: division by zero
|
|
219
|
+
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:32]: Show me, what value is wrong:
|
|
219
220
|
Traceback (most recent call last):
|
|
220
221
|
|
|
221
222
|
> File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
|
|
@@ -369,22 +370,22 @@ uvicorn main:app --host=0.0.0.0 --port=8000
|
|
|
369
370
|
**Output**:
|
|
370
371
|
|
|
371
372
|
```txt
|
|
372
|
-
[2023-09-01
|
|
373
|
-
[2023-09-01
|
|
374
|
-
[2023-09-01
|
|
375
|
-
[2023-09-01
|
|
376
|
-
[2023-09-01
|
|
377
|
-
[2023-09-01
|
|
378
|
-
[2023-09-01
|
|
379
|
-
[2023-09-01
|
|
380
|
-
[2023-09-01
|
|
381
|
-
[2023-09-01
|
|
382
|
-
^C[2023-09-01
|
|
383
|
-
[2023-09-01
|
|
384
|
-
[2023-09-01
|
|
385
|
-
[2023-09-01
|
|
386
|
-
[2023-09-01
|
|
387
|
-
[2023-09-01
|
|
373
|
+
[2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:576]: Intercepted modules: ['watchfiles.watcher', 'dotenv', 'asyncio', 'dotenv.main', 'watchfiles.main', 'concurrent.futures', 'uvicorn', 'fastapi', 'concurrent', 'watchfiles']; Muted modules: ['uvicorn.access', 'uvicorn.error'];
|
|
374
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:76]: Started server process [17146]
|
|
375
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:46]: Waiting for application startup.
|
|
376
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | main:21]: Preparing to startup...
|
|
377
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | main:22]: Finished preparation to startup.
|
|
378
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | main:23]: API version: 0.0.1-000000
|
|
379
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:60]: Application startup complete.
|
|
380
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:218]: Uvicorn running on http://0.0.0.0:9000 (Press CTRL+C to quit)
|
|
381
|
+
[2023-09-01 00:00:00.000 +09:00 | DEBUG | anyio._backends._asyncio:833]: [f635ebbc3f2348db9dcff681be1bd52a] 127.0.0.1 - "GET / HTTP/1.1"
|
|
382
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | anyio._backends._asyncio:833]: [f635ebbc3f2348db9dcff681be1bd52a] 127.0.0.1 - "GET / HTTP/1.1" 200 17B 0.7ms
|
|
383
|
+
^C[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:264]: Shutting down
|
|
384
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:65]: Waiting for application shutdown.
|
|
385
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | main:26]: Praparing to shutdown...
|
|
386
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | main:27]: Finished preparation to shutdown.
|
|
387
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:76]: Application shutdown complete.
|
|
388
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:86]: Finished server process [17146]
|
|
388
389
|
```
|
|
389
390
|
|
|
390
391
|
---
|
|
@@ -24,6 +24,7 @@ It is a `Loguru` based custom logging package for python projects.
|
|
|
24
24
|
- Add custom **handlers**
|
|
25
25
|
- **FastAPI** HTTP access logging **middleware**
|
|
26
26
|
- **Base** logging module
|
|
27
|
+
- Support **Pydantic-v1** and **Pydantic-v2**
|
|
27
28
|
|
|
28
29
|
---
|
|
29
30
|
|
|
@@ -181,16 +182,16 @@ python ./main.py
|
|
|
181
182
|
**Output**:
|
|
182
183
|
|
|
183
184
|
```txt
|
|
184
|
-
[2023-09-01
|
|
185
|
-
[2023-09-01
|
|
186
|
-
[2023-09-01
|
|
187
|
-
[2023-09-01
|
|
188
|
-
[2023-09-01
|
|
189
|
-
[2023-09-01
|
|
190
|
-
[2023-09-01
|
|
191
|
-
[2023-09-01
|
|
192
|
-
[2023-09-01
|
|
193
|
-
[2023-09-01
|
|
185
|
+
[2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:478]: Intercepted modules: ['concurrent', 'concurrent.futures', 'asyncio']; Muted modules: [];
|
|
186
|
+
[2023-09-01 00:00:00.000 +09:00 | TRACE | __main__:7]: Tracing...
|
|
187
|
+
[2023-09-01 00:00:00.000 +09:00 | DEBUG | __main__:8]: Debugging...
|
|
188
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | __main__:9]: Logging info.
|
|
189
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | __main__:10]: Success.
|
|
190
|
+
[2023-09-01 00:00:00.000 +09:00 | WARN | __main__:11]: Warning something.
|
|
191
|
+
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:12]: Error occured.
|
|
192
|
+
[2023-09-01 00:00:00.000 +09:00 | CRIT | __main__:13]: CRITICAL ERROR.
|
|
193
|
+
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:25]: division by zero
|
|
194
|
+
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:32]: Show me, what value is wrong:
|
|
194
195
|
Traceback (most recent call last):
|
|
195
196
|
|
|
196
197
|
> File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
|
|
@@ -344,22 +345,22 @@ uvicorn main:app --host=0.0.0.0 --port=8000
|
|
|
344
345
|
**Output**:
|
|
345
346
|
|
|
346
347
|
```txt
|
|
347
|
-
[2023-09-01
|
|
348
|
-
[2023-09-01
|
|
349
|
-
[2023-09-01
|
|
350
|
-
[2023-09-01
|
|
351
|
-
[2023-09-01
|
|
352
|
-
[2023-09-01
|
|
353
|
-
[2023-09-01
|
|
354
|
-
[2023-09-01
|
|
355
|
-
[2023-09-01
|
|
356
|
-
[2023-09-01
|
|
357
|
-
^C[2023-09-01
|
|
358
|
-
[2023-09-01
|
|
359
|
-
[2023-09-01
|
|
360
|
-
[2023-09-01
|
|
361
|
-
[2023-09-01
|
|
362
|
-
[2023-09-01
|
|
348
|
+
[2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:576]: Intercepted modules: ['watchfiles.watcher', 'dotenv', 'asyncio', 'dotenv.main', 'watchfiles.main', 'concurrent.futures', 'uvicorn', 'fastapi', 'concurrent', 'watchfiles']; Muted modules: ['uvicorn.access', 'uvicorn.error'];
|
|
349
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:76]: Started server process [17146]
|
|
350
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:46]: Waiting for application startup.
|
|
351
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | main:21]: Preparing to startup...
|
|
352
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | main:22]: Finished preparation to startup.
|
|
353
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | main:23]: API version: 0.0.1-000000
|
|
354
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:60]: Application startup complete.
|
|
355
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:218]: Uvicorn running on http://0.0.0.0:9000 (Press CTRL+C to quit)
|
|
356
|
+
[2023-09-01 00:00:00.000 +09:00 | DEBUG | anyio._backends._asyncio:833]: [f635ebbc3f2348db9dcff681be1bd52a] 127.0.0.1 - "GET / HTTP/1.1"
|
|
357
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | anyio._backends._asyncio:833]: [f635ebbc3f2348db9dcff681be1bd52a] 127.0.0.1 - "GET / HTTP/1.1" 200 17B 0.7ms
|
|
358
|
+
^C[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:264]: Shutting down
|
|
359
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:65]: Waiting for application shutdown.
|
|
360
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | main:26]: Praparing to shutdown...
|
|
361
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | main:27]: Finished preparation to shutdown.
|
|
362
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:76]: Application shutdown complete.
|
|
363
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:86]: Finished server process [17146]
|
|
363
364
|
```
|
|
364
365
|
|
|
365
366
|
---
|
beans_logging-4.3.1/beans_logging/schemas/config.py → beans_logging-4.3.2/beans_logging/schemas.py
RENAMED
|
@@ -3,21 +3,27 @@
|
|
|
3
3
|
import datetime
|
|
4
4
|
from typing import List
|
|
5
5
|
|
|
6
|
-
from pydantic import (
|
|
7
|
-
BaseModel,
|
|
8
|
-
constr,
|
|
9
|
-
Field,
|
|
10
|
-
field_validator,
|
|
11
|
-
model_validator,
|
|
12
|
-
ConfigDict,
|
|
13
|
-
)
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
from
|
|
7
|
+
import pydantic
|
|
8
|
+
from pydantic import BaseModel, constr, Field
|
|
9
|
+
|
|
10
|
+
if "2.0.0" <= pydantic.__version__:
|
|
11
|
+
from pydantic import field_validator, model_validator, ConfigDict
|
|
12
|
+
else:
|
|
13
|
+
from pydantic import validator, root_validator
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from ._consts import LogLevelEnum
|
|
17
|
+
from ._utils import get_default_logs_dir, get_app_name
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
class ExtraBaseModel(BaseModel):
|
|
20
|
-
|
|
21
|
+
if "2.0.0" <= pydantic.__version__:
|
|
22
|
+
model_config = ConfigDict(extra="allow")
|
|
23
|
+
else:
|
|
24
|
+
|
|
25
|
+
class Config:
|
|
26
|
+
extra = "allow"
|
|
21
27
|
|
|
22
28
|
|
|
23
29
|
class StdHandlerPM(ExtraBaseModel):
|
|
@@ -49,14 +55,26 @@ class LogHandlersPM(ExtraBaseModel):
|
|
|
49
55
|
default="{app_name}.std.err.log", min_length=4, max_length=1023
|
|
50
56
|
)
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
if "2.0.0" <= pydantic.__version__:
|
|
59
|
+
|
|
60
|
+
@model_validator(mode="after")
|
|
61
|
+
def _check_log_path(self) -> "LogHandlersPM":
|
|
62
|
+
if self.log_path == self.err_path:
|
|
63
|
+
raise ValueError(
|
|
64
|
+
f"`log_path` and `err_path` attributes are same: '{self.log_path}', must be different!"
|
|
65
|
+
)
|
|
66
|
+
return self
|
|
67
|
+
|
|
68
|
+
else:
|
|
58
69
|
|
|
59
|
-
|
|
70
|
+
@root_validator
|
|
71
|
+
def _check_log_path(cls, values):
|
|
72
|
+
_log_path, _err_path = values.get("log_path"), values.get("err_path")
|
|
73
|
+
if _log_path == _err_path:
|
|
74
|
+
raise ValueError(
|
|
75
|
+
f"`log_path` and `err_path` attributes are same: '{_log_path}', must be different!"
|
|
76
|
+
)
|
|
77
|
+
return values
|
|
60
78
|
|
|
61
79
|
|
|
62
80
|
class JsonHandlersPM(ExtraBaseModel):
|
|
@@ -69,14 +87,26 @@ class JsonHandlersPM(ExtraBaseModel):
|
|
|
69
87
|
default="{app_name}.json.err.log", min_length=4, max_length=1023
|
|
70
88
|
)
|
|
71
89
|
|
|
72
|
-
|
|
73
|
-
def _check_log_path(self) -> "JsonHandlersPM":
|
|
74
|
-
if self.log_path == self.err_path:
|
|
75
|
-
raise ValueError(
|
|
76
|
-
f"`log_path` and `err_path` attributes are same: '{self.log_path}', must be different!"
|
|
77
|
-
)
|
|
90
|
+
if "2.0.0" <= pydantic.__version__:
|
|
78
91
|
|
|
79
|
-
|
|
92
|
+
@model_validator(mode="after")
|
|
93
|
+
def _check_log_path(self) -> "JsonHandlersPM":
|
|
94
|
+
if self.log_path == self.err_path:
|
|
95
|
+
raise ValueError(
|
|
96
|
+
f"`log_path` and `err_path` attributes are same: '{self.log_path}', must be different!"
|
|
97
|
+
)
|
|
98
|
+
return self
|
|
99
|
+
|
|
100
|
+
else:
|
|
101
|
+
|
|
102
|
+
@root_validator
|
|
103
|
+
def _check_log_path(cls, values):
|
|
104
|
+
_log_path, _err_path = values.get("log_path"), values.get("err_path")
|
|
105
|
+
if _log_path == _err_path:
|
|
106
|
+
raise ValueError(
|
|
107
|
+
f"`log_path` and `err_path` attributes are same: '{_log_path}', must be different!"
|
|
108
|
+
)
|
|
109
|
+
return values
|
|
80
110
|
|
|
81
111
|
|
|
82
112
|
class FilePM(ExtraBaseModel):
|
|
@@ -94,12 +124,22 @@ class FilePM(ExtraBaseModel):
|
|
|
94
124
|
log_handlers: LogHandlersPM = Field(default_factory=LogHandlersPM)
|
|
95
125
|
json_handlers: JsonHandlersPM = Field(default_factory=JsonHandlersPM)
|
|
96
126
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
127
|
+
if "2.0.0" <= pydantic.__version__:
|
|
128
|
+
|
|
129
|
+
@field_validator("rotate_time", mode="before")
|
|
130
|
+
@classmethod
|
|
131
|
+
def _check_rotate_time(cls, val):
|
|
132
|
+
if isinstance(val, str):
|
|
133
|
+
val = datetime.time.fromisoformat(val)
|
|
134
|
+
return val
|
|
135
|
+
|
|
136
|
+
else:
|
|
137
|
+
|
|
138
|
+
@validator("rotate_time", pre=True, always=True)
|
|
139
|
+
def _check_rotate_time(cls, val):
|
|
140
|
+
if val and isinstance(val, str):
|
|
141
|
+
val = datetime.time.fromisoformat(val)
|
|
142
|
+
return val
|
|
103
143
|
|
|
104
144
|
|
|
105
145
|
class AutoLoadPM(ExtraBaseModel):
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: beans-logging
|
|
3
|
-
Version: 4.3.
|
|
3
|
+
Version: 4.3.2
|
|
4
4
|
Summary: 'beans_logging' is a python package for simple logger and easily managing logging modules. It is a Loguru based custom logging package for python projects.
|
|
5
5
|
Home-page: https://github.com/bybatkhuu/module.python-logging
|
|
6
|
-
Download-URL: https://github.com/bybatkhuu/module.python-logging/archive/v4.3.
|
|
6
|
+
Download-URL: https://github.com/bybatkhuu/module.python-logging/archive/v4.3.2.tar.gz
|
|
7
7
|
Author: Batkhuu Byambajav
|
|
8
8
|
Author-email: batkhuu10@gmail.com
|
|
9
9
|
License: MIT
|
|
@@ -49,6 +49,7 @@ It is a `Loguru` based custom logging package for python projects.
|
|
|
49
49
|
- Add custom **handlers**
|
|
50
50
|
- **FastAPI** HTTP access logging **middleware**
|
|
51
51
|
- **Base** logging module
|
|
52
|
+
- Support **Pydantic-v1** and **Pydantic-v2**
|
|
52
53
|
|
|
53
54
|
---
|
|
54
55
|
|
|
@@ -206,16 +207,16 @@ python ./main.py
|
|
|
206
207
|
**Output**:
|
|
207
208
|
|
|
208
209
|
```txt
|
|
209
|
-
[2023-09-01
|
|
210
|
-
[2023-09-01
|
|
211
|
-
[2023-09-01
|
|
212
|
-
[2023-09-01
|
|
213
|
-
[2023-09-01
|
|
214
|
-
[2023-09-01
|
|
215
|
-
[2023-09-01
|
|
216
|
-
[2023-09-01
|
|
217
|
-
[2023-09-01
|
|
218
|
-
[2023-09-01
|
|
210
|
+
[2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:478]: Intercepted modules: ['concurrent', 'concurrent.futures', 'asyncio']; Muted modules: [];
|
|
211
|
+
[2023-09-01 00:00:00.000 +09:00 | TRACE | __main__:7]: Tracing...
|
|
212
|
+
[2023-09-01 00:00:00.000 +09:00 | DEBUG | __main__:8]: Debugging...
|
|
213
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | __main__:9]: Logging info.
|
|
214
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | __main__:10]: Success.
|
|
215
|
+
[2023-09-01 00:00:00.000 +09:00 | WARN | __main__:11]: Warning something.
|
|
216
|
+
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:12]: Error occured.
|
|
217
|
+
[2023-09-01 00:00:00.000 +09:00 | CRIT | __main__:13]: CRITICAL ERROR.
|
|
218
|
+
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:25]: division by zero
|
|
219
|
+
[2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:32]: Show me, what value is wrong:
|
|
219
220
|
Traceback (most recent call last):
|
|
220
221
|
|
|
221
222
|
> File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
|
|
@@ -369,22 +370,22 @@ uvicorn main:app --host=0.0.0.0 --port=8000
|
|
|
369
370
|
**Output**:
|
|
370
371
|
|
|
371
372
|
```txt
|
|
372
|
-
[2023-09-01
|
|
373
|
-
[2023-09-01
|
|
374
|
-
[2023-09-01
|
|
375
|
-
[2023-09-01
|
|
376
|
-
[2023-09-01
|
|
377
|
-
[2023-09-01
|
|
378
|
-
[2023-09-01
|
|
379
|
-
[2023-09-01
|
|
380
|
-
[2023-09-01
|
|
381
|
-
[2023-09-01
|
|
382
|
-
^C[2023-09-01
|
|
383
|
-
[2023-09-01
|
|
384
|
-
[2023-09-01
|
|
385
|
-
[2023-09-01
|
|
386
|
-
[2023-09-01
|
|
387
|
-
[2023-09-01
|
|
373
|
+
[2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:576]: Intercepted modules: ['watchfiles.watcher', 'dotenv', 'asyncio', 'dotenv.main', 'watchfiles.main', 'concurrent.futures', 'uvicorn', 'fastapi', 'concurrent', 'watchfiles']; Muted modules: ['uvicorn.access', 'uvicorn.error'];
|
|
374
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:76]: Started server process [17146]
|
|
375
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:46]: Waiting for application startup.
|
|
376
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | main:21]: Preparing to startup...
|
|
377
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | main:22]: Finished preparation to startup.
|
|
378
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | main:23]: API version: 0.0.1-000000
|
|
379
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:60]: Application startup complete.
|
|
380
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:218]: Uvicorn running on http://0.0.0.0:9000 (Press CTRL+C to quit)
|
|
381
|
+
[2023-09-01 00:00:00.000 +09:00 | DEBUG | anyio._backends._asyncio:833]: [f635ebbc3f2348db9dcff681be1bd52a] 127.0.0.1 - "GET / HTTP/1.1"
|
|
382
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | anyio._backends._asyncio:833]: [f635ebbc3f2348db9dcff681be1bd52a] 127.0.0.1 - "GET / HTTP/1.1" 200 17B 0.7ms
|
|
383
|
+
^C[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:264]: Shutting down
|
|
384
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:65]: Waiting for application shutdown.
|
|
385
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | main:26]: Praparing to shutdown...
|
|
386
|
+
[2023-09-01 00:00:00.000 +09:00 | OK | main:27]: Finished preparation to shutdown.
|
|
387
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.lifespan.on:76]: Application shutdown complete.
|
|
388
|
+
[2023-09-01 00:00:00.000 +09:00 | INFO | uvicorn.server:86]: Finished server process [17146]
|
|
388
389
|
```
|
|
389
390
|
|
|
390
391
|
---
|
|
@@ -12,6 +12,7 @@ beans_logging/auto.py
|
|
|
12
12
|
beans_logging/filters.py
|
|
13
13
|
beans_logging/formats.py
|
|
14
14
|
beans_logging/rotation.py
|
|
15
|
+
beans_logging/schemas.py
|
|
15
16
|
beans_logging/sinks.py
|
|
16
17
|
beans_logging.egg-info/PKG-INFO
|
|
17
18
|
beans_logging.egg-info/SOURCES.txt
|
|
@@ -23,9 +24,6 @@ beans_logging/fastapi/_filters.py
|
|
|
23
24
|
beans_logging/fastapi/_formats.py
|
|
24
25
|
beans_logging/fastapi/_handlers.py
|
|
25
26
|
beans_logging/fastapi/_middlewares.py
|
|
26
|
-
beans_logging/schemas/__init__.py
|
|
27
|
-
beans_logging/schemas/config.py
|
|
28
|
-
beans_logging/schemas/config_v1.py
|
|
29
27
|
tests/__init__.py
|
|
30
28
|
tests/conftest.py
|
|
31
29
|
tests/test_beans_logging.py
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
import datetime
|
|
4
|
-
from typing import List
|
|
5
|
-
|
|
6
|
-
from pydantic import BaseModel, constr, Field, validator, root_validator
|
|
7
|
-
|
|
8
|
-
from .._consts import LogLevelEnum
|
|
9
|
-
from .._utils import get_default_logs_dir, get_app_name
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class ExtraBaseModel(BaseModel):
|
|
13
|
-
class Config:
|
|
14
|
-
extra = "allow"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class StdHandlerPM(ExtraBaseModel):
|
|
18
|
-
enabled: bool = Field(default=True)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class StreamPM(ExtraBaseModel):
|
|
22
|
-
use_color: bool = Field(default=True)
|
|
23
|
-
use_icon: bool = Field(default=False)
|
|
24
|
-
format_str: constr(strip_whitespace=True) = Field(
|
|
25
|
-
default="[<c>{time:YYYY-MM-DD HH:mm:ss.SSS Z}</c> | <level>{level_short:<5}</level> | <w>{name}:{line}</w>]: <level>{message}</level>",
|
|
26
|
-
min_length=3,
|
|
27
|
-
max_length=511,
|
|
28
|
-
)
|
|
29
|
-
std_handler: StdHandlerPM = Field(default_factory=StdHandlerPM)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class LogHandlersPM(ExtraBaseModel):
|
|
33
|
-
enabled: bool = Field(default=False)
|
|
34
|
-
format_str: constr(strip_whitespace=True) = Field(
|
|
35
|
-
default="[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {level_short:<5} | {name}:{line}]: {message}",
|
|
36
|
-
min_length=4,
|
|
37
|
-
max_length=511,
|
|
38
|
-
)
|
|
39
|
-
log_path: constr(strip_whitespace=True) = Field(
|
|
40
|
-
default="{app_name}.std.all.log", min_length=4, max_length=1023
|
|
41
|
-
)
|
|
42
|
-
err_path: constr(strip_whitespace=True) = Field(
|
|
43
|
-
default="{app_name}.std.err.log", min_length=4, max_length=1023
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
@root_validator
|
|
47
|
-
def _check_log_path(cls, values):
|
|
48
|
-
_log_path, _err_path = values.get("log_path"), values.get("err_path")
|
|
49
|
-
if _log_path == _err_path:
|
|
50
|
-
raise ValueError(
|
|
51
|
-
f"`log_path` and `err_path` attributes are same: '{_log_path}', must be different!"
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
return values
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
class JsonHandlersPM(ExtraBaseModel):
|
|
58
|
-
enabled: bool = Field(default=False)
|
|
59
|
-
use_custom: bool = Field(default=False)
|
|
60
|
-
log_path: constr(strip_whitespace=True) = Field(
|
|
61
|
-
default="{app_name}.json.all.log", min_length=4, max_length=1023
|
|
62
|
-
)
|
|
63
|
-
err_path: constr(strip_whitespace=True) = Field(
|
|
64
|
-
default="{app_name}.json.err.log", min_length=4, max_length=1023
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
@root_validator
|
|
68
|
-
def _check_log_path(cls, values):
|
|
69
|
-
_log_path, _err_path = values.get("log_path"), values.get("err_path")
|
|
70
|
-
if _log_path == _err_path:
|
|
71
|
-
raise ValueError(
|
|
72
|
-
f"`log_path` and `err_path` attributes are same: '{_log_path}', must be different!"
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
return values
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
class FilePM(ExtraBaseModel):
|
|
79
|
-
logs_dir: constr(strip_whitespace=True) = Field(
|
|
80
|
-
default_factory=get_default_logs_dir, min_length=2, max_length=1023
|
|
81
|
-
)
|
|
82
|
-
rotate_size: int = Field(
|
|
83
|
-
default=10_000_000, ge=1_000, lt=1_000_000_000 # 10MB = 10 * 1000 * 1000
|
|
84
|
-
)
|
|
85
|
-
rotate_time: datetime.time = Field(datetime.time(0, 0, 0))
|
|
86
|
-
backup_count: int = Field(default=90, ge=1)
|
|
87
|
-
encoding: constr(strip_whitespace=True) = Field(
|
|
88
|
-
default="utf8", min_length=2, max_length=31
|
|
89
|
-
)
|
|
90
|
-
log_handlers: LogHandlersPM = Field(default_factory=LogHandlersPM)
|
|
91
|
-
json_handlers: JsonHandlersPM = Field(default_factory=JsonHandlersPM)
|
|
92
|
-
|
|
93
|
-
@validator("rotate_time", pre=True, always=True)
|
|
94
|
-
def _check_rotate_time(cls, val):
|
|
95
|
-
if val and isinstance(val, str):
|
|
96
|
-
val = datetime.time.fromisoformat(val)
|
|
97
|
-
return val
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
class AutoLoadPM(ExtraBaseModel):
|
|
101
|
-
enabled: bool = Field(default=True)
|
|
102
|
-
only_base: bool = Field(default=False)
|
|
103
|
-
ignore_modules: List[str] = Field(default=[])
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
class InterceptPM(ExtraBaseModel):
|
|
107
|
-
auto_load: AutoLoadPM = Field(default_factory=AutoLoadPM)
|
|
108
|
-
include_modules: List[str] = Field(default=[])
|
|
109
|
-
mute_modules: List[str] = Field(default=[])
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
class ExtraPM(ExtraBaseModel):
|
|
113
|
-
pass
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
class LoggerConfigPM(ExtraBaseModel):
|
|
117
|
-
app_name: constr(strip_whitespace=True) = Field(
|
|
118
|
-
default_factory=get_app_name,
|
|
119
|
-
min_length=1,
|
|
120
|
-
max_length=127,
|
|
121
|
-
)
|
|
122
|
-
level: LogLevelEnum = Field(default=LogLevelEnum.INFO)
|
|
123
|
-
use_backtrace: bool = Field(default=True)
|
|
124
|
-
use_diagnose: bool = Field(default=False)
|
|
125
|
-
stream: StreamPM = Field(default_factory=StreamPM)
|
|
126
|
-
file: FilePM = Field(default_factory=FilePM)
|
|
127
|
-
intercept: InterceptPM = Field(default_factory=InterceptPM)
|
|
128
|
-
extra: ExtraPM = Field(default_factory=ExtraPM)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|