beans-logging 6.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.
@@ -1,3 +1 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- __version__ = "6.0.0"
1
+ __version__ = "6.0.1"
beans_logging/_base.py CHANGED
@@ -134,8 +134,8 @@ class LoggerLoader:
134
134
  ValueError: The `handler_type` argument value '{handler_type}' is invalid, must be 'NAME' or 'ID'!
135
135
 
136
136
  Args:
137
- handler (str, optional): Handler name or id to remove. Defaults to None.
138
- hadler_type (int, optional): Handler type to remove, must be 'NAME' or 'ID'. Defaults to 'name'.
137
+ handler (str, optional): Handler name or id to remove. Defaults to None.
138
+ handler_type (int, optional): Handler type to remove, must be 'NAME' or 'ID'. Defaults to 'name'.
139
139
  """
140
140
 
141
141
  if handler:
@@ -0,0 +1,419 @@
1
+ Metadata-Version: 2.4
2
+ Name: beans_logging
3
+ Version: 6.0.1
4
+ Summary: 'beans-logging' is a python package for simple logger and easily managing logging.
5
+ Author-email: Batkhuu Byambajav <batkhuu10@gmail.com>
6
+ Project-URL: Homepage, https://github.com/bybatkhuu/module-python-logging
7
+ Project-URL: Documentation, https://pylogging-docs.bybatkhuu.dev
8
+ Project-URL: Repository, https://github.com/bybatkhuu/module-python-logging.git
9
+ Project-URL: Issues, https://github.com/bybatkhuu/module-python-logging/issues
10
+ Project-URL: Changelog, https://github.com/bybatkhuu/module-python-logging/blob/main/CHANGELOG.md
11
+ Keywords: beans_logging,loguru,logging,logger,logs,python-logging,custom-logging
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Requires-Python: <4.0,>=3.10
22
+ Description-Content-Type: text/markdown
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
26
+ Requires-Dist: loguru<1.0.0,>=0.7.3
27
+ Provides-Extra: fastapi
28
+ Requires-Dist: beans-logging-fastapi<2.0.0,>=1.0.0; extra == "fastapi"
29
+ Provides-Extra: test
30
+ Requires-Dist: pytest<9.0.0,>=8.0.2; extra == "test"
31
+ Requires-Dist: pytest-cov<8.0.0,>=5.0.0; extra == "test"
32
+ Requires-Dist: pytest-xdist<4.0.0,>=3.6.1; extra == "test"
33
+ Requires-Dist: pytest-benchmark<6.0.0,>=5.0.1; extra == "test"
34
+ Provides-Extra: build
35
+ Requires-Dist: setuptools<81.0.0,>=70.3.0; extra == "build"
36
+ Requires-Dist: wheel<1.0.0,>=0.43.0; extra == "build"
37
+ Requires-Dist: build<2.0.0,>=1.1.1; extra == "build"
38
+ Requires-Dist: twine<7.0.0,>=6.0.1; extra == "build"
39
+ Provides-Extra: docs
40
+ Requires-Dist: pylint<4.0.0,>=3.0.4; extra == "docs"
41
+ Requires-Dist: mkdocs-material<10.0.0,>=9.5.50; extra == "docs"
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"
44
+ Requires-Dist: mike<3.0.0,>=2.1.3; extra == "docs"
45
+ Provides-Extra: dev
46
+ Requires-Dist: pytest<9.0.0,>=8.0.2; extra == "dev"
47
+ Requires-Dist: pytest-cov<8.0.0,>=5.0.0; extra == "dev"
48
+ Requires-Dist: pytest-xdist<4.0.0,>=3.6.1; extra == "dev"
49
+ Requires-Dist: pytest-benchmark<6.0.0,>=5.0.1; extra == "dev"
50
+ Requires-Dist: setuptools<81.0.0,>=70.3.0; extra == "dev"
51
+ Requires-Dist: wheel<1.0.0,>=0.43.0; extra == "dev"
52
+ Requires-Dist: build<2.0.0,>=1.1.1; extra == "dev"
53
+ Requires-Dist: twine<7.0.0,>=6.0.1; extra == "dev"
54
+ Requires-Dist: pylint<4.0.0,>=3.0.4; extra == "dev"
55
+ Requires-Dist: mkdocs-material<10.0.0,>=9.5.50; extra == "dev"
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"
58
+ Requires-Dist: mike<3.0.0,>=2.1.3; extra == "dev"
59
+ Requires-Dist: pyright<2.0.0,>=1.1.392; extra == "dev"
60
+ Requires-Dist: pre-commit<5.0.0,>=4.0.1; extra == "dev"
61
+ Dynamic: license-file
62
+
63
+ # Python Logging (beans-logging)
64
+
65
+ [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit)
66
+ [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bybatkhuu/module-python-logging/2.build-publish.yml?logo=GitHub)](https://github.com/bybatkhuu/module-python-logging/actions/workflows/2.build-publish.yml)
67
+ [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/bybatkhuu/module-python-logging?logo=GitHub&color=blue)](https://github.com/bybatkhuu/module-python-logging/releases)
68
+ [![PyPI](https://img.shields.io/pypi/v/beans-logging?logo=PyPi)](https://pypi.org/project/beans-logging)
69
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/beans-logging?logo=Python)](https://docs.conda.io/en/latest/miniconda.html)
70
+
71
+ `beans-logging` is a python package for simple logger and easily managing logs.
72
+
73
+ It is a `Loguru` based custom logging package for python projects.
74
+
75
+ ## ✨ Features
76
+
77
+ - Main **logger** based on **Loguru** logging - <https://pypi.org/project/loguru>
78
+ - Logging to **log files** (all, error, json)
79
+ - **Pre-defined** logging configs and handlers
80
+ - **Colorful** logging
81
+ - Auto **intercepting** and **muting** modules
82
+ - Load config from **YAML** or **JSON** file
83
+ - Custom options as a **config**
84
+ - Custom logging **formats**
85
+ - **Multiprocess** compatibility (Linux, macOS - 'fork')
86
+ - Add custom **handlers**
87
+ - **Base** logging module
88
+
89
+ ---
90
+
91
+ ## 🛠 Installation
92
+
93
+ ### 1. 🚧 Prerequisites
94
+
95
+ - Install **Python (>= v3.10)** and **pip (>= 23)**:
96
+ - **[RECOMMENDED] [Miniconda (v3)](https://www.anaconda.com/docs/getting-started/miniconda/install)**
97
+ - *[arm64/aarch64] [Miniforge (v3)](https://github.com/conda-forge/miniforge)*
98
+ - *[Python virutal environment] [venv](https://docs.python.org/3/library/venv.html)*
99
+
100
+ [OPTIONAL] For **DEVELOPMENT** environment:
101
+
102
+ - Install [**git**](https://git-scm.com/downloads)
103
+ - Setup an [**SSH key**](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh) ([video tutorial](https://www.youtube.com/watch?v=snCP3c7wXw0))
104
+
105
+ ### 2. 📥 Download or clone the repository
106
+
107
+ [TIP] Skip this step, if you're going to install the package directly from **PyPi** or **GitHub** repository.
108
+
109
+ **2.1.** Prepare projects directory (if not exists):
110
+
111
+ ```sh
112
+ # Create projects directory:
113
+ mkdir -pv ~/workspaces/projects
114
+
115
+ # Enter into projects directory:
116
+ cd ~/workspaces/projects
117
+ ```
118
+
119
+ **2.2.** Follow one of the below options **[A]**, **[B]** or **[C]**:
120
+
121
+ **OPTION A.** Clone the repository:
122
+
123
+ ```sh
124
+ git clone https://github.com/bybatkhuu/module-python-logging.git && \
125
+ cd module-python-logging
126
+ ```
127
+
128
+ **OPTION B.** Clone the repository (for **DEVELOPMENT**: git + ssh key):
129
+
130
+ ```sh
131
+ git clone git@github.com:bybatkhuu/module-python-logging.git && \
132
+ cd module-python-logging
133
+ ```
134
+
135
+ **OPTION C.** Download source code:
136
+
137
+ 1. Download archived **zip** file from [**releases**](https://github.com/bybatkhuu/module-python-logging/releases).
138
+ 2. Extract it into the projects directory.
139
+
140
+ ### 3. 📦 Install the package
141
+
142
+ [NOTE] Choose one of the following methods to install the package **[A ~ F]**:
143
+
144
+ **OPTION A.** [**RECOMMENDED**] Install from **PyPi**:
145
+
146
+ ```sh
147
+ pip install -U beans-logging
148
+ ```
149
+
150
+ **OPTION B.** Install latest version directly from **GitHub** repository:
151
+
152
+ ```sh
153
+ pip install git+https://github.com/bybatkhuu/module-python-logging.git
154
+ ```
155
+
156
+ **OPTION C.** Install from the downloaded **source code**:
157
+
158
+ ```sh
159
+ # Install directly from the source code:
160
+ pip install .
161
+
162
+ # Or install with editable mode:
163
+ pip install -e .
164
+ ```
165
+
166
+ **OPTION D.** Install for **DEVELOPMENT** environment:
167
+
168
+ ```sh
169
+ pip install -e .[dev]
170
+
171
+ # Install pre-commit hooks:
172
+ pre-commit install
173
+ ```
174
+
175
+ **OPTION E.** Install from **pre-built release** files:
176
+
177
+ 1. Download **`.whl`** or **`.tar.gz`** file from [**releases**](https://github.com/bybatkhuu/module-python-logging/releases)
178
+ 2. Install with pip:
179
+
180
+ ```sh
181
+ # Install from .whl file:
182
+ pip install ./beans_logging-[VERSION]-py3-none-any.whl
183
+
184
+ # Or install from .tar.gz file:
185
+ pip install ./beans_logging-[VERSION].tar.gz
186
+ ```
187
+
188
+ **OPTION F.** Copy the **module** into the project directory (for **testing**):
189
+
190
+ ```sh
191
+ # Install python dependencies:
192
+ pip install -r ./requirements.txt
193
+
194
+ # Copy the module source code into the project:
195
+ cp -r ./src/beans_logging [PROJECT_DIR]
196
+ # For example:
197
+ cp -r ./src/beans_logging /some/path/project/
198
+ ```
199
+
200
+ ## 🚸 Usage/Examples
201
+
202
+ To use `beans_logging`, import the `logger` instance from the `beans_logging.auto` package:
203
+
204
+ ```python
205
+ from beans_logging.auto import logger
206
+ ```
207
+
208
+ You can call logging methods directly from the `logger` instance:
209
+
210
+ ```python
211
+ logger.info("Logging info.")
212
+ ```
213
+
214
+ ### **Simple**
215
+
216
+ [**`configs/logger.yml`**](https://github.com/bybatkhuu/module-python-logging/blob/main/examples/simple/configs/logger.yml):
217
+
218
+ ```yml
219
+ logger:
220
+ app_name: "my-app"
221
+ level: "TRACE"
222
+ file:
223
+ log_handlers:
224
+ enabled: true
225
+ json_handlers:
226
+ enabled: true
227
+ ```
228
+
229
+ [**`main.py`**](https://github.com/bybatkhuu/module-python-logging/blob/main/examples/simple/main.py):
230
+
231
+ ```python
232
+ from beans_logging.auto import logger
233
+
234
+
235
+ logger.trace("Tracing...")
236
+ logger.debug("Debugging...")
237
+ logger.info("Logging info.")
238
+ logger.success("Success.")
239
+ logger.warning("Warning something.")
240
+ logger.error("Error occured.")
241
+ logger.critical("CRITICAL ERROR.")
242
+
243
+ def divide(a, b):
244
+ _result = a / b
245
+ return _result
246
+
247
+ def nested(c):
248
+ try:
249
+ divide(5, c)
250
+ except ZeroDivisionError as err:
251
+ logger.error(err)
252
+ raise
253
+
254
+ try:
255
+ nested(0)
256
+ except Exception as err:
257
+ logger.exception("Show me, what value is wrong:")
258
+ ```
259
+
260
+ Run the [**`examples/simple`**](https://github.com/bybatkhuu/module-python-logging/tree/main/examples/simple):
261
+
262
+ ```sh
263
+ cd ./examples/simple
264
+
265
+ python ./main.py
266
+ ```
267
+
268
+ **Output**:
269
+
270
+ ```txt
271
+ [2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:478]: Intercepted modules: ['concurrent', 'concurrent.futures', 'asyncio']; Muted modules: [];
272
+ [2023-09-01 00:00:00.000 +09:00 | TRACE | __main__:7]: Tracing...
273
+ [2023-09-01 00:00:00.000 +09:00 | DEBUG | __main__:8]: Debugging...
274
+ [2023-09-01 00:00:00.000 +09:00 | INFO | __main__:9]: Logging info.
275
+ [2023-09-01 00:00:00.000 +09:00 | OK | __main__:10]: Success.
276
+ [2023-09-01 00:00:00.000 +09:00 | WARN | __main__:11]: Warning something.
277
+ [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:12]: Error occured.
278
+ [2023-09-01 00:00:00.000 +09:00 | CRIT | __main__:13]: CRITICAL ERROR.
279
+ [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:25]: division by zero
280
+ [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:32]: Show me, what value is wrong:
281
+ Traceback (most recent call last):
282
+
283
+ > File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
284
+ nested(0)
285
+ └ <function nested at 0x10802a4c0>
286
+
287
+ File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 23, in nested
288
+ divide(5, c)
289
+ │ └ 0
290
+ └ <function divide at 0x1052f31f0>
291
+
292
+ File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 17, in divide
293
+ _result = a / b
294
+ │ └ 0
295
+ └ 5
296
+
297
+ ZeroDivisionError: division by zero
298
+ ```
299
+
300
+ 👍
301
+
302
+ ---
303
+
304
+ ## ⚙️ Configuration
305
+
306
+ [**`templates/configs/config.yml`**](./templates/configs/config.yml):
307
+
308
+ ```yaml
309
+ logger:
310
+ # app_name: "app"
311
+ level: "INFO"
312
+ use_diagnose: false
313
+ stream:
314
+ use_color: true
315
+ use_icon: false
316
+ 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>"
317
+ std_handler:
318
+ enabled: true
319
+ file:
320
+ logs_dir: "./logs"
321
+ rotate_size: 10000000 # 10MB
322
+ rotate_time: "00:00:00"
323
+ backup_count: 90
324
+ log_handlers:
325
+ enabled: false
326
+ format_str: "[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {level_short:<5} | {name}:{line}]: {message}"
327
+ log_path: "{app_name}.std.all.log"
328
+ err_path: "{app_name}.std.err.log"
329
+ json_handlers:
330
+ enabled: false
331
+ use_custom: false
332
+ log_path: "{app_name}.json.all.log"
333
+ err_path: "{app_name}.json.err.log"
334
+ intercept:
335
+ auto_load:
336
+ enabled: true
337
+ only_base: false
338
+ ignore_modules: []
339
+ include_modules: []
340
+ mute_modules: []
341
+ extra:
342
+ ```
343
+
344
+ ### 🌎 Environment Variables
345
+
346
+ [**`.env.example`**](./.env.example):
347
+
348
+ ```sh
349
+ # ENV=LOCAL
350
+ # DEBUG=false
351
+ # TZ=UTC
352
+
353
+ # BEANS_LOGGING_DISABLE_DEFAULT=false
354
+ # BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml"
355
+ # BEANS_LOGGING_LOGS_DIR="./logs"
356
+ ```
357
+
358
+ ---
359
+
360
+ ## 🧪 Running Tests
361
+
362
+ To run tests, run the following command:
363
+
364
+ ```sh
365
+ # Install python test dependencies:
366
+ pip install .[test]
367
+
368
+ # Run tests:
369
+ python -m pytest -sv -o log_cli=true
370
+ # Or use the test script:
371
+ ./scripts/test.sh -l -v -c
372
+ ```
373
+
374
+ ## 🏗️ Build Package
375
+
376
+ To build the python package, run the following command:
377
+
378
+ ```sh
379
+ # Install python build dependencies:
380
+ pip install -r ./requirements/requirements.build.txt
381
+
382
+ # Build python package:
383
+ python -m build
384
+ # Or use the build script:
385
+ ./scripts/build.sh
386
+ ```
387
+
388
+ ## 📝 Generate Docs
389
+
390
+ To build the documentation, run the following command:
391
+
392
+ ```sh
393
+ # Install python documentation dependencies:
394
+ pip install -r ./requirements/requirements.docs.txt
395
+
396
+ # Serve documentation locally (for development):
397
+ mkdocs serve -a 0.0.0.0:8000
398
+ # Or use the docs script:
399
+ ./scripts/docs.sh
400
+
401
+ # Or build documentation:
402
+ mkdocs build
403
+ # Or use the docs script:
404
+ ./scripts/docs.sh -b
405
+ ```
406
+
407
+ ## 📚 Documentation
408
+
409
+ - [Docs](./docs)
410
+
411
+ ---
412
+
413
+ ## 📑 References
414
+
415
+ - <https://github.com/Delgan/loguru>
416
+ - <https://loguru.readthedocs.io/en/stable/api/logger.html>
417
+ - <https://loguru.readthedocs.io/en/stable/resources/recipes.html>
418
+ - <https://docs.python.org/3/library/logging.html>
419
+ - <https://github.com/bybatkhuu/module-fastapi-logging>
@@ -0,0 +1,17 @@
1
+ beans_logging/__init__.py,sha256=TxuozMCLvGkG7sATP2uFCQws6TRqwp36yc08zUVGcb4,297
2
+ beans_logging/__version__.py,sha256=unmO3xtN2S1e9meUbIjG3AZVyKxUe4HSZNXDOcpZRJg,22
3
+ beans_logging/_base.py,sha256=_4mllOq9hr65Aq7OUkQU3OPTtPvmpv-4x47J6oWN9TI,24573
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-6.0.1.dist-info/licenses/LICENSE.txt,sha256=CUTK-r0BWIg1r0bBiemAcMhakgV0N7HuRhw6rQ-A9A4,1074
14
+ beans_logging-6.0.1.dist-info/METADATA,sha256=qbUyyqgbutJ9qHsPrFge6pIsXUeomPoQB-qkpgYto74,12877
15
+ beans_logging-6.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ beans_logging-6.0.1.dist-info/top_level.txt,sha256=lx8JEqYGNha1sYbVrTtMo2Z01A7Shq8hX6bfsuKLTG8,14
17
+ beans_logging-6.0.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.3)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Batkhuu Byambajav
3
+ Copyright (c) 2025 Batkhuu Byambajav
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,326 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: beans-logging
3
- Version: 6.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/v6.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
- Provides-Extra: fastapi
26
- Requires-Dist: beans-logging-fastapi <2.0.0,>=1.0.0 ; extra == 'fastapi'
27
-
28
- # beans_logging
29
-
30
- [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
31
- [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bybatkhuu/module.python-logging/2.build-publish.yml?logo=GitHub)](https://github.com/bybatkhuu/module.python-logging/actions/workflows/2.build-publish.yml)
32
- [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/bybatkhuu/module.python-logging?logo=GitHub)](https://github.com/bybatkhuu/module.python-logging/releases)
33
- [![PyPI](https://img.shields.io/pypi/v/beans-logging?logo=PyPi)](https://pypi.org/project/beans-logging)
34
- [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/beans-logging?logo=Python)](https://docs.conda.io/en/latest/miniconda.html)
35
-
36
- `beans_logging` is a python package for simple logger and easily managing logging modules.
37
-
38
- It is a `Loguru` based custom logging package for python projects.
39
-
40
- ## Features
41
-
42
- - Main **logger** based on **Loguru** logging - <https://pypi.org/project/loguru>
43
- - Logging to **log files** (all, error, json)
44
- - **Pre-defined** logging configs and handlers
45
- - **Colorful** logging
46
- - Auto **intercepting** and **muting** modules
47
- - Load config from **YAML** or **JSON** file
48
- - Custom options as a **config**
49
- - Custom logging **formats**
50
- - **Multiprocess** compatibility (Linux, macOS - 'fork')
51
- - Add custom **handlers**
52
- - **Base** logging module
53
- - Support **Pydantic-v1** and **Pydantic-v2**
54
-
55
- ---
56
-
57
- ## Installation
58
-
59
- ### 1. Prerequisites
60
-
61
- - **Python (>= v3.8)**
62
- - **PyPi (>= v23)**
63
-
64
- ### 2. Install beans-logging package
65
-
66
- Choose one of the following methods to install the package **[A ~ F]**:
67
-
68
- **A.** [**RECOMMENDED**] Install from **PyPi**
69
-
70
- ```sh
71
- # Install or upgrade beans-logging package:
72
- pip install -U beans-logging
73
- ```
74
-
75
- **B.** Install latest version from **GitHub**
76
-
77
- ```sh
78
- # Install package by git:
79
- pip install git+https://github.com/bybatkhuu/module.python-logging.git
80
- ```
81
-
82
- **C.** Install from **pre-built release** files
83
-
84
- 1. Download **`.whl`** or **`.tar.gz`** file from **releases** - <https://github.com/bybatkhuu/module.python-logging/releases>
85
- 2. Install with pip:
86
-
87
- ```sh
88
- # Install from .whl file:
89
- pip install ./beans_logging-[VERSION]-py3-none-any.whl
90
- # Or install from .tar.gz file:
91
- pip install ./beans_logging-[VERSION].tar.gz
92
- ```
93
-
94
- **D.** Install from **source code** by building package
95
-
96
- ```sh
97
- # Clone repository by git:
98
- git clone https://github.com/bybatkhuu/module.python-logging.git beans_logging
99
- cd ./beans_logging
100
-
101
- # Install python build tool:
102
- pip install -U pip build
103
-
104
- # Build python package:
105
- python -m build
106
-
107
- _VERSION=$(./scripts/get-version.sh)
108
-
109
- # Install from .whl file:
110
- pip install ./dist/beans_logging-${_VERSION}-py3-none-any.whl
111
- # Or install from .tar.gz file:
112
- pip install ./dist/beans_logging-${_VERSION}.tar.gz
113
- ```
114
-
115
- **E.** Install with pip editable **development mode** (from source code)
116
-
117
- ```sh
118
- # Clone repository by git:
119
- git clone https://github.com/bybatkhuu/module.python-logging.git beans_logging
120
- cd ./beans_logging
121
-
122
- # Install with editable development mode:
123
- pip install -e .
124
- ```
125
-
126
- **F.** Manually add to **PYTHONPATH** (not recommended)
127
-
128
- ```sh
129
- # Clone repository by git:
130
- git clone https://github.com/bybatkhuu/module.python-logging.git beans_logging
131
- cd ./beans_logging
132
-
133
- # Install python dependencies:
134
- pip install -r ./requirements.txt
135
-
136
- # Add current path to PYTHONPATH:
137
- export PYTHONPATH="${PWD}:${PYTHONPATH}"
138
- ```
139
-
140
- ## Usage/Examples
141
-
142
- To use `beans_logging`, import the `logger` instance from the `beans_logging.auto` package:
143
-
144
- ```python
145
- from beans_logging.auto import logger
146
- ```
147
-
148
- You can call logging methods directly from the `logger` instance:
149
-
150
- ```python
151
- logger.info("Logging info.")
152
- ```
153
-
154
- ### **Simple**
155
-
156
- [**`configs/logger.yml`**](https://github.com/bybatkhuu/module.python-logging/blob/main/examples/simple/configs/logger.yml):
157
-
158
- ```yml
159
- logger:
160
- app_name: "my-app"
161
- level: "TRACE"
162
- file:
163
- log_handlers:
164
- enabled: true
165
- json_handlers:
166
- enabled: true
167
- ```
168
-
169
- [**`main.py`**](https://github.com/bybatkhuu/module.python-logging/blob/main/examples/simple/main.py):
170
-
171
- ```python
172
- from beans_logging.auto import logger
173
-
174
-
175
- logger.trace("Tracing...")
176
- logger.debug("Debugging...")
177
- logger.info("Logging info.")
178
- logger.success("Success.")
179
- logger.warning("Warning something.")
180
- logger.error("Error occured.")
181
- logger.critical("CRITICAL ERROR.")
182
-
183
- def divide(a, b):
184
- _result = a / b
185
- return _result
186
-
187
- def nested(c):
188
- try:
189
- divide(5, c)
190
- except ZeroDivisionError as err:
191
- logger.error(err)
192
- raise
193
-
194
- try:
195
- nested(0)
196
- except Exception as err:
197
- logger.exception("Show me, what value is wrong:")
198
- ```
199
-
200
- Run the [**`examples/simple`**](https://github.com/bybatkhuu/module.python-logging/tree/main/examples/simple):
201
-
202
- ```sh
203
- cd ./examples/simple
204
-
205
- python ./main.py
206
- ```
207
-
208
- **Output**:
209
-
210
- ```txt
211
- [2023-09-01 00:00:00.000 +09:00 | TRACE | beans_logging._base:478]: Intercepted modules: ['concurrent', 'concurrent.futures', 'asyncio']; Muted modules: [];
212
- [2023-09-01 00:00:00.000 +09:00 | TRACE | __main__:7]: Tracing...
213
- [2023-09-01 00:00:00.000 +09:00 | DEBUG | __main__:8]: Debugging...
214
- [2023-09-01 00:00:00.000 +09:00 | INFO | __main__:9]: Logging info.
215
- [2023-09-01 00:00:00.000 +09:00 | OK | __main__:10]: Success.
216
- [2023-09-01 00:00:00.000 +09:00 | WARN | __main__:11]: Warning something.
217
- [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:12]: Error occured.
218
- [2023-09-01 00:00:00.000 +09:00 | CRIT | __main__:13]: CRITICAL ERROR.
219
- [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:25]: division by zero
220
- [2023-09-01 00:00:00.000 +09:00 | ERROR | __main__:32]: Show me, what value is wrong:
221
- Traceback (most recent call last):
222
-
223
- > File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
224
- nested(0)
225
- └ <function nested at 0x10802a4c0>
226
-
227
- File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 23, in nested
228
- divide(5, c)
229
- │ └ 0
230
- └ <function divide at 0x1052f31f0>
231
-
232
- File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 17, in divide
233
- _result = a / b
234
- │ └ 0
235
- └ 5
236
-
237
- ZeroDivisionError: division by zero
238
- ```
239
-
240
- ### **FastAPI**
241
-
242
- Checkout `beans_logging_fastapi` package: <https://github.com/bybatkhuu/module.fastapi-logging>
243
-
244
- - FastAPI HTTP access logging middleware
245
- - Install with pip: `pip install -U beans-logging[fastapi]` or `pip install -U beans-logging-fastapi`
246
-
247
- ---
248
-
249
- ## Running Tests
250
-
251
- To run tests, run the following command:
252
-
253
- ```sh
254
- # Install python test dependencies:
255
- pip install -r ./requirements.test.txt
256
-
257
- # Run tests:
258
- python -m pytest -v
259
- ```
260
-
261
- ## Environment Variables
262
-
263
- You can use the following environment variables inside [**`.env.example`**](https://github.com/bybatkhuu/module.python-logging/blob/main/.env.example) file:
264
-
265
- ```sh
266
- ENV=development
267
- DEBUG=true
268
-
269
- BEANS_LOGGING_DISABLE_DEFAULT=false
270
- BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml"
271
- BEANS_LOGGING_LOGS_DIR="./logs"
272
- ```
273
-
274
- ## Configuration
275
-
276
- You can use the following configuration template [**`logger.yml`**](https://github.com/bybatkhuu/module.python-logging/blob/main/templates/configs/logger.yml): file:
277
-
278
- ```yaml
279
- logger:
280
- # app_name: "app"
281
- level: "INFO"
282
- use_diagnose: false
283
- stream:
284
- use_color: true
285
- use_icon: false
286
- 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>"
287
- std_handler:
288
- enabled: true
289
- file:
290
- logs_dir: "./logs"
291
- rotate_size: 10000000 # 10MB
292
- rotate_time: "00:00:00"
293
- backup_count: 90
294
- log_handlers:
295
- enabled: false
296
- format_str: "[{time:YYYY-MM-DD HH:mm:ss.SSS Z} | {level_short:<5} | {name}:{line}]: {message}"
297
- log_path: "{app_name}.std.all.log"
298
- err_path: "{app_name}.std.err.log"
299
- json_handlers:
300
- enabled: false
301
- use_custom: false
302
- log_path: "{app_name}.json.all.log"
303
- err_path: "{app_name}.json.err.log"
304
- intercept:
305
- auto_load:
306
- enabled: true
307
- only_base: false
308
- ignore_modules: []
309
- include_modules: []
310
- mute_modules: []
311
- extra:
312
- ```
313
-
314
- ## Documentation
315
-
316
- - [docs](https://github.com/bybatkhuu/module.python-logging/blob/main/docs/README.md)
317
- - [scripts](https://github.com/bybatkhuu/module.python-logging/blob/main/docs/scripts/README.md)
318
-
319
- ---
320
-
321
- ## References
322
-
323
- - <https://github.com/Delgan/loguru>
324
- - <https://loguru.readthedocs.io/en/stable/api/logger.html>
325
- - <https://loguru.readthedocs.io/en/stable/resources/recipes.html>
326
- - <https://github.com/bybatkhuu/module.fastapi-logging>
@@ -1,20 +0,0 @@
1
- beans_logging/__init__.py,sha256=TxuozMCLvGkG7sATP2uFCQws6TRqwp36yc08zUVGcb4,297
2
- beans_logging/__version__.py,sha256=Skn1HZtKosF7bkVFNvpnIh3dEl9kV9eFp7ZGRzT6uQI,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
- tests/__init__.py,sha256=iwhKnzeBJLKxpRVjvzwiRE63_zNpIBfaKLITauVph-0,24
14
- tests/conftest.py,sha256=ycEL83-UMU-fcXQUZWTCNEPcBOZ38pzhoCPpXpCjIEM,319
15
- tests/test_beans_logging.py,sha256=qyiM24QEAi7lVs-QBmjh_e48bCHk8nNYwMOlZIb6phw,1733
16
- beans_logging-6.0.0.dist-info/LICENSE.txt,sha256=8jrXqC7FZbke39LPGo_mUFR81CkoUCP_vyefZjlQDOg,1074
17
- beans_logging-6.0.0.dist-info/METADATA,sha256=jd6oaW9K3_v7vYmOt3RnGf3HODeTwkGrERzxwSCsMCM,9805
18
- beans_logging-6.0.0.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
19
- beans_logging-6.0.0.dist-info/top_level.txt,sha256=wSVo6vZwIqyOwwsbVBQceBQ_VJKuErw8OQvDiHcp8uU,20
20
- beans_logging-6.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!")
@@ -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")