beans-logging 5.0.0__py3-none-any.whl → 6.0.1__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.
- beans_logging/__version__.py +1 -3
- beans_logging/_base.py +2 -2
- beans_logging-6.0.1.dist-info/METADATA +419 -0
- beans_logging-6.0.1.dist-info/RECORD +17 -0
- {beans_logging-5.0.0.dist-info → beans_logging-6.0.1.dist-info}/WHEEL +1 -1
- {beans_logging-5.0.0.dist-info → beans_logging-6.0.1.dist-info/licenses}/LICENSE.txt +1 -1
- {beans_logging-5.0.0.dist-info → beans_logging-6.0.1.dist-info}/top_level.txt +0 -1
- beans_logging/fastapi/__init__.py +0 -6
- beans_logging/fastapi/_filters.py +0 -22
- beans_logging/fastapi/_formats.py +0 -62
- beans_logging/fastapi/_handlers.py +0 -79
- beans_logging/fastapi/_middlewares.py +0 -262
- beans_logging-5.0.0.dist-info/METADATA +0 -469
- beans_logging-5.0.0.dist-info/RECORD +0 -25
- tests/__init__.py +0 -1
- tests/conftest.py +0 -16
- tests/test_beans_logging.py +0 -67
|
@@ -1,469 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: beans-logging
|
|
3
|
-
Version: 5.0.0
|
|
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
|
-
Home-page: https://github.com/bybatkhuu/module.python-logging
|
|
6
|
-
Download-URL: https://github.com/bybatkhuu/module.python-logging/archive/v5.0.0.tar.gz
|
|
7
|
-
Author: Batkhuu Byambajav
|
|
8
|
-
Author-email: batkhuu10@gmail.com
|
|
9
|
-
License: MIT
|
|
10
|
-
Keywords: beans_logging,loguru,logging,logger,logs,log,print,custom-logging
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Topic :: Software Development :: Build Tools
|
|
14
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Requires-Python: >=3.8
|
|
20
|
-
Description-Content-Type: text/markdown
|
|
21
|
-
License-File: LICENSE.txt
|
|
22
|
-
Requires-Dist: PyYAML <7.0,>=6.0
|
|
23
|
-
Requires-Dist: pydantic !=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.10.0
|
|
24
|
-
Requires-Dist: loguru <1.0.0,>=0.7.2
|
|
25
|
-
|
|
26
|
-
# beans_logging
|
|
27
|
-
|
|
28
|
-
[](https://choosealicense.com/licenses/mit/)
|
|
29
|
-
[](https://github.com/bybatkhuu/module.python-logging/actions/workflows/2.build-publish.yml)
|
|
30
|
-
[](https://github.com/bybatkhuu/module.python-logging/releases)
|
|
31
|
-
[](https://pypi.org/project/beans-logging)
|
|
32
|
-
[](https://docs.conda.io/en/latest/miniconda.html)
|
|
33
|
-
|
|
34
|
-
`beans_logging` is a python package for simple logger and easily managing logging modules.
|
|
35
|
-
|
|
36
|
-
It is a `Loguru` based custom logging package for python projects.
|
|
37
|
-
|
|
38
|
-
## Features
|
|
39
|
-
|
|
40
|
-
- Main **logger** based on **Loguru** logging - <https://pypi.org/project/loguru>
|
|
41
|
-
- Logging to **log files** (all, error, json)
|
|
42
|
-
- **Pre-defined** logging configs and handlers
|
|
43
|
-
- **Colorful** logging
|
|
44
|
-
- Auto **intercepting** and **muting** modules
|
|
45
|
-
- Load config from **YAML** or **JSON** file
|
|
46
|
-
- Custom options as a **config**
|
|
47
|
-
- Custom logging **formats**
|
|
48
|
-
- **Multiprocess** compatibility (Linux, macOS - 'fork')
|
|
49
|
-
- Add custom **handlers**
|
|
50
|
-
- **FastAPI** HTTP access logging **middleware**
|
|
51
|
-
- **Base** logging module
|
|
52
|
-
- Support **Pydantic-v1** and **Pydantic-v2**
|
|
53
|
-
|
|
54
|
-
---
|
|
55
|
-
|
|
56
|
-
## Installation
|
|
57
|
-
|
|
58
|
-
### 1. Prerequisites
|
|
59
|
-
|
|
60
|
-
- **Python (>= v3.8)**
|
|
61
|
-
- **PyPi (>= v23)**
|
|
62
|
-
|
|
63
|
-
### 2. Install beans-logging package
|
|
64
|
-
|
|
65
|
-
Choose one of the following methods to install the package **[A ~ F]**:
|
|
66
|
-
|
|
67
|
-
**A.** [**RECOMMENDED**] Install from **PyPi**
|
|
68
|
-
|
|
69
|
-
```sh
|
|
70
|
-
# Install or upgrade beans-logging package:
|
|
71
|
-
pip install -U beans-logging
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
**B.** Install latest version from **GitHub**
|
|
75
|
-
|
|
76
|
-
```sh
|
|
77
|
-
# Install package by git:
|
|
78
|
-
pip install git+https://github.com/bybatkhuu/module.python-logging.git
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
**C.** Install from **pre-built release** files
|
|
82
|
-
|
|
83
|
-
1. Download **`.whl`** or **`.tar.gz`** file from **releases** - <https://github.com/bybatkhuu/module.python-logging/releases>
|
|
84
|
-
2. Install with pip:
|
|
85
|
-
|
|
86
|
-
```sh
|
|
87
|
-
# Install from .whl file:
|
|
88
|
-
pip install ./beans_logging-[VERSION]-py3-none-any.whl
|
|
89
|
-
# Or install from .tar.gz file:
|
|
90
|
-
pip install ./beans_logging-[VERSION].tar.gz
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
**D.** Install from **source code** by building package
|
|
94
|
-
|
|
95
|
-
```sh
|
|
96
|
-
# Clone repository by git:
|
|
97
|
-
git clone https://github.com/bybatkhuu/module.python-logging.git beans_logging
|
|
98
|
-
cd ./beans_logging
|
|
99
|
-
|
|
100
|
-
# Install python build tool:
|
|
101
|
-
pip install -U pip build
|
|
102
|
-
|
|
103
|
-
# Build python package:
|
|
104
|
-
python -m build
|
|
105
|
-
|
|
106
|
-
_VERSION=$(./scripts/get-version.sh)
|
|
107
|
-
|
|
108
|
-
# Install from .whl file:
|
|
109
|
-
pip install ./dist/beans_logging-${_VERSION}-py3-none-any.whl
|
|
110
|
-
# Or install from .tar.gz file:
|
|
111
|
-
pip install ./dist/beans_logging-${_VERSION}.tar.gz
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
**E.** Install with pip editable **development mode** (from source code)
|
|
115
|
-
|
|
116
|
-
```sh
|
|
117
|
-
# Clone repository by git:
|
|
118
|
-
git clone https://github.com/bybatkhuu/module.python-logging.git beans_logging
|
|
119
|
-
cd ./beans_logging
|
|
120
|
-
|
|
121
|
-
# Install with editable development mode:
|
|
122
|
-
pip install -e .
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
**F.** Manually add to **PYTHONPATH** (not recommended)
|
|
126
|
-
|
|
127
|
-
```sh
|
|
128
|
-
# Clone repository by git:
|
|
129
|
-
git clone https://github.com/bybatkhuu/module.python-logging.git beans_logging
|
|
130
|
-
cd ./beans_logging
|
|
131
|
-
|
|
132
|
-
# Install python dependencies:
|
|
133
|
-
pip install -r ./requirements.txt
|
|
134
|
-
|
|
135
|
-
# Add current path to PYTHONPATH:
|
|
136
|
-
export PYTHONPATH="${PWD}:${PYTHONPATH}"
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
## Usage/Examples
|
|
140
|
-
|
|
141
|
-
To use `beans_logging`, import the `logger` instance from the `beans_logging.auto` package:
|
|
142
|
-
|
|
143
|
-
```python
|
|
144
|
-
from beans_logging.auto import logger
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
You can call logging methods directly from the `logger` instance:
|
|
148
|
-
|
|
149
|
-
```python
|
|
150
|
-
logger.info("Logging info.")
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### **Simple**
|
|
154
|
-
|
|
155
|
-
[**`configs/logger.yml`**](https://github.com/bybatkhuu/module.python-logging/blob/main/examples/simple/configs/logger.yml):
|
|
156
|
-
|
|
157
|
-
```yml
|
|
158
|
-
logger:
|
|
159
|
-
app_name: "my-app"
|
|
160
|
-
level: "TRACE"
|
|
161
|
-
file:
|
|
162
|
-
log_handlers:
|
|
163
|
-
enabled: true
|
|
164
|
-
json_handlers:
|
|
165
|
-
enabled: true
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
[**`main.py`**](https://github.com/bybatkhuu/module.python-logging/blob/main/examples/simple/main.py):
|
|
169
|
-
|
|
170
|
-
```python
|
|
171
|
-
from beans_logging.auto import logger
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
logger.trace("Tracing...")
|
|
175
|
-
logger.debug("Debugging...")
|
|
176
|
-
logger.info("Logging info.")
|
|
177
|
-
logger.success("Success.")
|
|
178
|
-
logger.warning("Warning something.")
|
|
179
|
-
logger.error("Error occured.")
|
|
180
|
-
logger.critical("CRITICAL ERROR.")
|
|
181
|
-
|
|
182
|
-
def divide(a, b):
|
|
183
|
-
_result = a / b
|
|
184
|
-
return _result
|
|
185
|
-
|
|
186
|
-
def nested(c):
|
|
187
|
-
try:
|
|
188
|
-
divide(5, c)
|
|
189
|
-
except ZeroDivisionError as err:
|
|
190
|
-
logger.error(err)
|
|
191
|
-
raise
|
|
192
|
-
|
|
193
|
-
try:
|
|
194
|
-
nested(0)
|
|
195
|
-
except Exception as err:
|
|
196
|
-
logger.exception("Show me, what value is wrong:")
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
Run the [**`examples/simple`**](https://github.com/bybatkhuu/module.python-logging/tree/main/examples/simple):
|
|
200
|
-
|
|
201
|
-
```sh
|
|
202
|
-
cd ./examples/simple
|
|
203
|
-
|
|
204
|
-
python ./main.py
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
**Output**:
|
|
208
|
-
|
|
209
|
-
```txt
|
|
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:
|
|
220
|
-
Traceback (most recent call last):
|
|
221
|
-
|
|
222
|
-
> File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
|
|
223
|
-
nested(0)
|
|
224
|
-
└ <function nested at 0x10802a4c0>
|
|
225
|
-
|
|
226
|
-
File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 23, in nested
|
|
227
|
-
divide(5, c)
|
|
228
|
-
│ └ 0
|
|
229
|
-
└ <function divide at 0x1052f31f0>
|
|
230
|
-
|
|
231
|
-
File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 17, in divide
|
|
232
|
-
_result = a / b
|
|
233
|
-
│ └ 0
|
|
234
|
-
└ 5
|
|
235
|
-
|
|
236
|
-
ZeroDivisionError: division by zero
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
### **Advanced (FastAPI)**
|
|
240
|
-
|
|
241
|
-
[**`configs/logger.yml`**](https://github.com/bybatkhuu/module.python-logging/blob/main/examples/advanced/configs/logger.yml):
|
|
242
|
-
|
|
243
|
-
```yaml
|
|
244
|
-
logger:
|
|
245
|
-
app_name: "fastapi-app"
|
|
246
|
-
level: "TRACE"
|
|
247
|
-
use_diagnose: false
|
|
248
|
-
stream:
|
|
249
|
-
use_color: true
|
|
250
|
-
use_icon: false
|
|
251
|
-
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>"
|
|
252
|
-
std_handler:
|
|
253
|
-
enabled: true
|
|
254
|
-
file:
|
|
255
|
-
logs_dir: "./logs"
|
|
256
|
-
rotate_size: 10000000 # 10MB
|
|
257
|
-
rotate_time: "00:00:00"
|
|
258
|
-
backup_count: 90
|
|
259
|
-
log_handlers:
|
|
260
|
-
enabled: true
|
|
261
|
-
format_str: "[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {level_short:<5} | {name}:{line}]: {message}"
|
|
262
|
-
log_path: "{app_name}.std.all.log"
|
|
263
|
-
err_path: "{app_name}.std.err.log"
|
|
264
|
-
json_handlers:
|
|
265
|
-
enabled: true
|
|
266
|
-
use_custom: false
|
|
267
|
-
log_path: "json/{app_name}.json.all.log"
|
|
268
|
-
err_path: "json/{app_name}.json.err.log"
|
|
269
|
-
intercept:
|
|
270
|
-
auto_load:
|
|
271
|
-
enabled: true
|
|
272
|
-
only_base: false
|
|
273
|
-
ignore_modules: []
|
|
274
|
-
include_modules: []
|
|
275
|
-
mute_modules: ["uvicorn.access", "uvicorn.error"]
|
|
276
|
-
extra:
|
|
277
|
-
http_std_debug_format: '<n>[{request_id}]</n> {client_host} {user_id} "<u>{method} {url_path}</u> HTTP/{http_version}"'
|
|
278
|
-
http_std_msg_format: '<n><w>[{request_id}]</w></n> {client_host} {user_id} "<u>{method} {url_path}</u> HTTP/{http_version}" {status_code} {content_length}B {response_time}ms'
|
|
279
|
-
http_file_enabled: true
|
|
280
|
-
http_log_path: "http/{app_name}.http.access.log"
|
|
281
|
-
http_err_path: "http/{app_name}.http.err.log"
|
|
282
|
-
http_json_enabled: true
|
|
283
|
-
http_json_path: "json.http/{app_name}.json.http.access.log"
|
|
284
|
-
http_json_err_path: "json.http/{app_name}.json.http.err.log"
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
[**`.env`**](https://github.com/bybatkhuu/module.python-logging/blob/main/examples/advanced/.env):
|
|
288
|
-
|
|
289
|
-
```sh
|
|
290
|
-
ENV=development
|
|
291
|
-
DEBUG=true
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
[**`logger.py`**](https://github.com/bybatkhuu/module.python-logging/blob/main/examples/advanced/logger.py):
|
|
295
|
-
|
|
296
|
-
```python
|
|
297
|
-
from beans_logging import Logger, LoggerLoader
|
|
298
|
-
from beans_logging.fastapi import add_http_file_handler, add_http_file_json_handler
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
logger_loader = LoggerLoader()
|
|
302
|
-
logger: Logger = logger_loader.load()
|
|
303
|
-
|
|
304
|
-
if logger_loader.config.extra.http_file_enabled:
|
|
305
|
-
add_http_file_handler(
|
|
306
|
-
logger_loader=logger_loader,
|
|
307
|
-
log_path=logger_loader.config.extra.http_log_path,
|
|
308
|
-
err_path=logger_loader.config.extra.http_err_path,
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
if logger_loader.config.extra.http_json_enabled:
|
|
312
|
-
add_http_file_json_handler(
|
|
313
|
-
logger_loader=logger_loader,
|
|
314
|
-
log_path=logger_loader.config.extra.http_json_path,
|
|
315
|
-
err_path=logger_loader.config.extra.http_json_err_path,
|
|
316
|
-
)
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
[**`main.py`**](https://github.com/bybatkhuu/module.python-logging/blob/main/examples/advanced/main.py):
|
|
320
|
-
|
|
321
|
-
```python
|
|
322
|
-
from typing import Union
|
|
323
|
-
from contextlib import asynccontextmanager
|
|
324
|
-
|
|
325
|
-
from dotenv import load_dotenv
|
|
326
|
-
from fastapi import FastAPI, HTTPException
|
|
327
|
-
from fastapi.responses import RedirectResponse
|
|
328
|
-
|
|
329
|
-
load_dotenv()
|
|
330
|
-
|
|
331
|
-
from beans_logging.fastapi import HttpAccessLogMiddleware
|
|
332
|
-
|
|
333
|
-
from logger import logger, logger_loader
|
|
334
|
-
from __version__ import __version__
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
@asynccontextmanager
|
|
338
|
-
async def lifespan(app: FastAPI):
|
|
339
|
-
logger.info("Preparing to startup...")
|
|
340
|
-
logger.success("Finished preparation to startup.")
|
|
341
|
-
logger.info(f"API version: {__version__}")
|
|
342
|
-
|
|
343
|
-
yield
|
|
344
|
-
logger.info("Praparing to shutdown...")
|
|
345
|
-
logger.success("Finished preparation to shutdown.")
|
|
346
|
-
|
|
347
|
-
app = FastAPI(lifespan=lifespan, version=__version__)
|
|
348
|
-
app.add_middleware(
|
|
349
|
-
HttpAccessLogMiddleware,
|
|
350
|
-
has_proxy_headers=True,
|
|
351
|
-
debug_format=logger_loader.config.extra.http_std_debug_format,
|
|
352
|
-
msg_format=logger_loader.config.extra.http_std_msg_format,
|
|
353
|
-
)
|
|
354
|
-
|
|
355
|
-
@app.get("/")
|
|
356
|
-
def root():
|
|
357
|
-
return {"Hello": "World"}
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
Run the [**`examples/advanced`**](https://github.com/bybatkhuu/module.python-logging/tree/main/examples/advanced):
|
|
361
|
-
|
|
362
|
-
```sh
|
|
363
|
-
cd ./examples/advanced
|
|
364
|
-
# Install python dependencies for examples:
|
|
365
|
-
pip install -r ./requirements.txt
|
|
366
|
-
|
|
367
|
-
uvicorn main:app --host=0.0.0.0 --port=8000
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
**Output**:
|
|
371
|
-
|
|
372
|
-
```txt
|
|
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]
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
---
|
|
392
|
-
|
|
393
|
-
## Running Tests
|
|
394
|
-
|
|
395
|
-
To run tests, run the following command:
|
|
396
|
-
|
|
397
|
-
```sh
|
|
398
|
-
# Install python test dependencies:
|
|
399
|
-
pip install -r ./requirements.test.txt
|
|
400
|
-
|
|
401
|
-
# Run tests:
|
|
402
|
-
python -m pytest -v
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
## Environment Variables
|
|
406
|
-
|
|
407
|
-
You can use the following environment variables inside [**`.env.example`**](https://github.com/bybatkhuu/module.python-logging/blob/main/.env.example) file:
|
|
408
|
-
|
|
409
|
-
```sh
|
|
410
|
-
ENV=development
|
|
411
|
-
DEBUG=true
|
|
412
|
-
|
|
413
|
-
BEANS_LOGGING_DISABLE_DEFAULT=false
|
|
414
|
-
BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml"
|
|
415
|
-
BEANS_LOGGING_LOGS_DIR="./logs"
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
## Configuration
|
|
419
|
-
|
|
420
|
-
You can use the following configuration template [**`logger.yml`**](https://github.com/bybatkhuu/module.python-logging/blob/main/templates/configs/logger.yml): file:
|
|
421
|
-
|
|
422
|
-
```yaml
|
|
423
|
-
logger:
|
|
424
|
-
# app_name: "app"
|
|
425
|
-
level: "INFO"
|
|
426
|
-
use_diagnose: false
|
|
427
|
-
stream:
|
|
428
|
-
use_color: true
|
|
429
|
-
use_icon: false
|
|
430
|
-
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>"
|
|
431
|
-
std_handler:
|
|
432
|
-
enabled: true
|
|
433
|
-
file:
|
|
434
|
-
logs_dir: "./logs"
|
|
435
|
-
rotate_size: 10000000 # 10MB
|
|
436
|
-
rotate_time: "00:00:00"
|
|
437
|
-
backup_count: 90
|
|
438
|
-
log_handlers:
|
|
439
|
-
enabled: false
|
|
440
|
-
format_str: "[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {level_short:<5} | {name}:{line}]: {message}"
|
|
441
|
-
log_path: "{app_name}.std.all.log"
|
|
442
|
-
err_path: "{app_name}.std.err.log"
|
|
443
|
-
json_handlers:
|
|
444
|
-
enabled: false
|
|
445
|
-
use_custom: false
|
|
446
|
-
log_path: "{app_name}.json.all.log"
|
|
447
|
-
err_path: "{app_name}.json.err.log"
|
|
448
|
-
intercept:
|
|
449
|
-
auto_load:
|
|
450
|
-
enabled: true
|
|
451
|
-
only_base: false
|
|
452
|
-
ignore_modules: []
|
|
453
|
-
include_modules: []
|
|
454
|
-
mute_modules: []
|
|
455
|
-
extra:
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
## Documentation
|
|
459
|
-
|
|
460
|
-
- [docs](https://github.com/bybatkhuu/module.python-logging/blob/main/docs/README.md)
|
|
461
|
-
- [scripts](https://github.com/bybatkhuu/module.python-logging/blob/main/docs/scripts/README.md)
|
|
462
|
-
|
|
463
|
-
---
|
|
464
|
-
|
|
465
|
-
## References
|
|
466
|
-
|
|
467
|
-
- <https://github.com/Delgan/loguru>
|
|
468
|
-
- <https://loguru.readthedocs.io/en/stable/api/logger.html>
|
|
469
|
-
- <https://loguru.readthedocs.io/en/stable/resources/recipes.html>
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
beans_logging/__init__.py,sha256=TxuozMCLvGkG7sATP2uFCQws6TRqwp36yc08zUVGcb4,297
|
|
2
|
-
beans_logging/__version__.py,sha256=K0fs4J5NJ5WU4JVVBd7HB1kDa9KbSFtg4q_yyI8M-pg,47
|
|
3
|
-
beans_logging/_base.py,sha256=HEf9Vyyj3oS0m5wuKd50LQDCVZNmsBEM1LntrYbnGjs,24571
|
|
4
|
-
beans_logging/_consts.py,sha256=b_-uytryZFCxlD2aKXzdS0oQpAsaK6JLi-w5bUeG1yE,345
|
|
5
|
-
beans_logging/_handlers.py,sha256=WQjr-dGAnjsegI2LHJl_Fubxb0reSCr8A6IvR7eN8dk,1133
|
|
6
|
-
beans_logging/_utils.py,sha256=Smb0cxkTdVxA-IE-oqi3sGhpsQdtNquQSw2bQxN0pDM,2742
|
|
7
|
-
beans_logging/auto.py,sha256=Wyi4w4qZ9PNW2dDF19E8qoKuZVfhyAEl_rVPzMscVCM,534
|
|
8
|
-
beans_logging/filters.py,sha256=YNUF5_0hE0XoPfLCi5wQFe1Qi7eLV0UaJUtCDwlG5ec,3369
|
|
9
|
-
beans_logging/formats.py,sha256=gxyJT9ZUWQvjrL4x6fU5bLKybGsFkCpFDG5OpndqDhc,1349
|
|
10
|
-
beans_logging/rotation.py,sha256=GspZX7wff_igZjbGSysCboz8fUgDHofGRL10OaNlZ3I,2137
|
|
11
|
-
beans_logging/schemas.py,sha256=syMsmwbDvDE1odnaIX18PEIEpWyItfDDnisZr1AsOPs,5641
|
|
12
|
-
beans_logging/sinks.py,sha256=C_y53i_QJuNZs_zBitb87d_tfsLhin2D9DtImPV5OHg,356
|
|
13
|
-
beans_logging/fastapi/__init__.py,sha256=rK10G__Ery8lTujJLkRjLO_OTJX8o0QLAf5xNRKrXhw,248
|
|
14
|
-
beans_logging/fastapi/_filters.py,sha256=BNkIxCW1_GkmrpZdIH7SsP69_p989_ru0kjjBB7LKzg,509
|
|
15
|
-
beans_logging/fastapi/_formats.py,sha256=xyz8fiultiB4SVOnvxt-6kW3nb3LsIv-3YeKbJj-xmg,1727
|
|
16
|
-
beans_logging/fastapi/_handlers.py,sha256=eoV-fDKgmZHBV3IfcV01rirH29Devd8DqnvTgzZCZpc,2726
|
|
17
|
-
beans_logging/fastapi/_middlewares.py,sha256=UkFrpKP8XbtXE2lJU7F3N0XuJF48awkL7CCdNtf657I,11315
|
|
18
|
-
tests/__init__.py,sha256=iwhKnzeBJLKxpRVjvzwiRE63_zNpIBfaKLITauVph-0,24
|
|
19
|
-
tests/conftest.py,sha256=ycEL83-UMU-fcXQUZWTCNEPcBOZ38pzhoCPpXpCjIEM,319
|
|
20
|
-
tests/test_beans_logging.py,sha256=qyiM24QEAi7lVs-QBmjh_e48bCHk8nNYwMOlZIb6phw,1733
|
|
21
|
-
beans_logging-5.0.0.dist-info/LICENSE.txt,sha256=8jrXqC7FZbke39LPGo_mUFR81CkoUCP_vyefZjlQDOg,1074
|
|
22
|
-
beans_logging-5.0.0.dist-info/METADATA,sha256=PWKVVgAIsDcWto2ntWhC_2tRZDtisu6bUD2pnIxk0UU,15296
|
|
23
|
-
beans_logging-5.0.0.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
|
|
24
|
-
beans_logging-5.0.0.dist-info/top_level.txt,sha256=wSVo6vZwIqyOwwsbVBQceBQ_VJKuErw8OQvDiHcp8uU,20
|
|
25
|
-
beans_logging-5.0.0.dist-info/RECORD,,
|
tests/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
tests/conftest.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
|
|
5
|
-
from beans_logging import logger
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@pytest.fixture(scope="session", autouse=True)
|
|
9
|
-
def setup_and_teardown():
|
|
10
|
-
# Equivalent of setUp
|
|
11
|
-
logger.info("Setting up...")
|
|
12
|
-
|
|
13
|
-
yield # This is where the testing happens!
|
|
14
|
-
|
|
15
|
-
# Equivalent of tearDown
|
|
16
|
-
logger.info("Tearing down!")
|
tests/test_beans_logging.py
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
|
|
5
|
-
from beans_logging import Logger, LoggerConfigPM, LoggerLoader
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@pytest.fixture
|
|
9
|
-
def logger_loader():
|
|
10
|
-
_logger_loader = LoggerLoader()
|
|
11
|
-
|
|
12
|
-
yield _logger_loader
|
|
13
|
-
|
|
14
|
-
del _logger_loader
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@pytest.fixture
|
|
18
|
-
def logger():
|
|
19
|
-
from beans_logging import logger
|
|
20
|
-
|
|
21
|
-
yield logger
|
|
22
|
-
|
|
23
|
-
del logger
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def test_init(logger: Logger, logger_loader: LoggerLoader):
|
|
27
|
-
logger.info("Testing initialization of 'LoggerLoader'...")
|
|
28
|
-
|
|
29
|
-
assert isinstance(logger_loader, LoggerLoader)
|
|
30
|
-
assert logger_loader.handlers_map == {"default": 0}
|
|
31
|
-
assert logger_loader.config_file_path == LoggerLoader._CONFIG_FILE_PATH
|
|
32
|
-
assert isinstance(logger_loader.config, LoggerConfigPM)
|
|
33
|
-
|
|
34
|
-
logger.success("Done: Initialization of 'LoggerLoader'.\n")
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def test_load(logger: Logger, logger_loader: LoggerLoader):
|
|
38
|
-
logger.info("Testing 'load' method of 'LoggerLoader'...")
|
|
39
|
-
|
|
40
|
-
logger_loader.update_config(config={"level": "TRACE"})
|
|
41
|
-
_logger: Logger = logger_loader.load()
|
|
42
|
-
|
|
43
|
-
assert isinstance(_logger, Logger)
|
|
44
|
-
assert _logger == logger
|
|
45
|
-
_logger.trace("Tracing...")
|
|
46
|
-
_logger.debug("Debugging...")
|
|
47
|
-
_logger.info("Logging info.")
|
|
48
|
-
_logger.success("Success.")
|
|
49
|
-
_logger.warning("Warning something.")
|
|
50
|
-
_logger.error("Error occured.")
|
|
51
|
-
_logger.critical("CRITICAL ERROR.")
|
|
52
|
-
|
|
53
|
-
logger.success("Done: 'load' method.\n")
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def test_methods(logger: Logger):
|
|
57
|
-
logger.info("Testing 'logger' methods...")
|
|
58
|
-
|
|
59
|
-
logger.trace("Tracing...")
|
|
60
|
-
logger.debug("Debugging...")
|
|
61
|
-
logger.info("Logging info.")
|
|
62
|
-
logger.success("Success.")
|
|
63
|
-
logger.warning("Warning something.")
|
|
64
|
-
logger.error("Error occured.")
|
|
65
|
-
logger.critical("CRITICAL ERROR.")
|
|
66
|
-
|
|
67
|
-
logger.success("Done: 'logger' methods.\n")
|