beans-logging 6.0.0__tar.gz → 6.0.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.
Files changed (40) hide show
  1. beans_logging-6.0.2/.python-version +1 -0
  2. {beans_logging-6.0.0 → beans_logging-6.0.2}/LICENSE.txt +1 -1
  3. beans_logging-6.0.2/PKG-INFO +424 -0
  4. {beans_logging-6.0.0 → beans_logging-6.0.2}/README.md +158 -95
  5. beans_logging-6.0.2/auto.py +6 -0
  6. beans_logging-6.0.2/pyproject.toml +66 -0
  7. beans_logging-6.0.2/requirements/requirements.build.txt +4 -0
  8. beans_logging-6.0.2/requirements/requirements.dev.txt +2 -0
  9. beans_logging-6.0.2/requirements/requirements.docs.txt +5 -0
  10. beans_logging-6.0.2/requirements/requirements.fastapi.txt +1 -0
  11. beans_logging-6.0.2/requirements/requirements.test.txt +4 -0
  12. beans_logging-6.0.2/requirements.txt +3 -0
  13. beans_logging-6.0.2/setup.py +3 -0
  14. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/__init__.py +0 -2
  15. beans_logging-6.0.2/src/beans_logging/__version__.py +1 -0
  16. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/_base.py +37 -41
  17. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/_consts.py +0 -2
  18. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/_handlers.py +2 -4
  19. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/_utils.py +2 -3
  20. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/auto.py +2 -3
  21. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/filters.py +0 -3
  22. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/formats.py +0 -2
  23. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/rotation.py +2 -4
  24. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/schemas.py +7 -7
  25. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging/sinks.py +0 -2
  26. beans_logging-6.0.2/src/beans_logging.egg-info/PKG-INFO +424 -0
  27. beans_logging-6.0.2/src/beans_logging.egg-info/SOURCES.txt +36 -0
  28. beans_logging-6.0.2/src/beans_logging.egg-info/requires.txt +42 -0
  29. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging.egg-info/top_level.txt +1 -1
  30. beans_logging-6.0.0/PKG-INFO +0 -326
  31. beans_logging-6.0.0/beans_logging/__version__.py +0 -3
  32. beans_logging-6.0.0/beans_logging.egg-info/PKG-INFO +0 -326
  33. beans_logging-6.0.0/beans_logging.egg-info/SOURCES.txt +0 -24
  34. beans_logging-6.0.0/beans_logging.egg-info/requires.txt +0 -6
  35. beans_logging-6.0.0/setup.py +0 -54
  36. beans_logging-6.0.0/tests/__init__.py +0 -1
  37. beans_logging-6.0.0/tests/conftest.py +0 -16
  38. beans_logging-6.0.0/tests/test_beans_logging.py +0 -67
  39. {beans_logging-6.0.0 → beans_logging-6.0.2}/setup.cfg +0 -0
  40. {beans_logging-6.0.0 → beans_logging-6.0.2/src}/beans_logging.egg-info/dependency_links.txt +0 -0
@@ -0,0 +1 @@
1
+ 3.10
@@ -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
@@ -0,0 +1,424 @@
1
+ Metadata-Version: 2.4
2
+ Name: beans_logging
3
+ Version: 6.0.2
4
+ Summary: 'beans-logging' is a python package for simple logger and easily managing logs.
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)
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`**](./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`**](./examples/simple/main.py):
230
+
231
+ ```python
232
+ #!/usr/bin/env python
233
+
234
+ from beans_logging.auto import logger
235
+
236
+
237
+ logger.trace("Tracing...")
238
+ logger.debug("Debugging...")
239
+ logger.info("Logging info.")
240
+ logger.success("Success.")
241
+ logger.warning("Warning something.")
242
+ logger.error("Error occured.")
243
+ logger.critical("CRITICAL ERROR.")
244
+
245
+
246
+ def divide(a, b):
247
+ _result = a / b
248
+ return _result
249
+
250
+
251
+ def nested(c):
252
+ try:
253
+ divide(5, c)
254
+ except ZeroDivisionError as err:
255
+ logger.error(err)
256
+ raise
257
+
258
+
259
+ try:
260
+ nested(0)
261
+ except Exception:
262
+ logger.exception("Show me, what value is wrong:")
263
+ ```
264
+
265
+ Run the [**`examples/simple`**](./examples/simple):
266
+
267
+ ```sh
268
+ cd ./examples/simple
269
+
270
+ python ./main.py
271
+ ```
272
+
273
+ **Output**:
274
+
275
+ ```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:
286
+ Traceback (most recent call last):
287
+
288
+ > File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 30, in <module>
289
+ nested(0)
290
+ └ <function nested at 0x10802a4c0>
291
+
292
+ File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 23, in nested
293
+ divide(5, c)
294
+ │ └ 0
295
+ └ <function divide at 0x1052f31f0>
296
+
297
+ File "/home/user/workspaces/projects/beans_logging/examples/simple/./main.py", line 17, in divide
298
+ _result = a / b
299
+ │ └ 0
300
+ └ 5
301
+
302
+ ZeroDivisionError: division by zero
303
+ ```
304
+
305
+ 👍
306
+
307
+ ---
308
+
309
+ ## ⚙️ Configuration
310
+
311
+ [**`templates/configs/logger.yml`**](./templates/configs/logger.yml):
312
+
313
+ ```yaml
314
+ 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"
339
+ intercept:
340
+ auto_load:
341
+ enabled: true
342
+ only_base: false
343
+ ignore_modules: []
344
+ include_modules: []
345
+ mute_modules: []
346
+ extra:
347
+ ```
348
+
349
+ ### 🌎 Environment Variables
350
+
351
+ [**`.env.example`**](./.env.example):
352
+
353
+ ```sh
354
+ # ENV=LOCAL
355
+ # DEBUG=false
356
+ # TZ=UTC
357
+
358
+ # BEANS_LOGGING_DISABLE_DEFAULT=false
359
+ # BEANS_LOGGING_CONFIG_PATH="./configs/logger.yml"
360
+ # BEANS_LOGGING_LOGS_DIR="./logs"
361
+ ```
362
+
363
+ ---
364
+
365
+ ## 🧪 Running Tests
366
+
367
+ To run tests, run the following command:
368
+
369
+ ```sh
370
+ # Install python test dependencies:
371
+ pip install .[test]
372
+
373
+ # Run tests:
374
+ python -m pytest -sv -o log_cli=true
375
+ # Or use the test script:
376
+ ./scripts/test.sh -l -v -c
377
+ ```
378
+
379
+ ## 🏗️ Build Package
380
+
381
+ To build the python package, run the following command:
382
+
383
+ ```sh
384
+ # Install python build dependencies:
385
+ pip install -r ./requirements/requirements.build.txt
386
+
387
+ # Build python package:
388
+ python -m build
389
+ # Or use the build script:
390
+ ./scripts/build.sh
391
+ ```
392
+
393
+ ## 📝 Generate Docs
394
+
395
+ To build the documentation, run the following command:
396
+
397
+ ```sh
398
+ # Install python documentation dependencies:
399
+ pip install -r ./requirements/requirements.docs.txt
400
+
401
+ # Serve documentation locally (for development):
402
+ mkdocs serve -a 0.0.0.0:8000
403
+ # Or use the docs script:
404
+ ./scripts/docs.sh
405
+
406
+ # Or build documentation:
407
+ mkdocs build
408
+ # Or use the docs script:
409
+ ./scripts/docs.sh -b
410
+ ```
411
+
412
+ ## 📚 Documentation
413
+
414
+ - [Docs](./docs)
415
+
416
+ ---
417
+
418
+ ## 📑 References
419
+
420
+ - <https://github.com/Delgan/loguru>
421
+ - <https://loguru.readthedocs.io/en/stable/api/logger.html>
422
+ - <https://loguru.readthedocs.io/en/stable/resources/recipes.html>
423
+ - <https://docs.python.org/3/library/logging.html>
424
+ - <https://github.com/bybatkhuu/module-fastapi-logging>