pythonLogs 5.0.2__tar.gz → 6.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,160 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ .idea/
157
+
158
+ # Custom
159
+ /junit.xml
160
+ *.prof
@@ -0,0 +1,402 @@
1
+ Metadata-Version: 2.4
2
+ Name: pythonLogs
3
+ Version: 6.0.0
4
+ Summary: High-performance Python logging library with file rotation and optimized caching for better performance
5
+ Project-URL: Homepage, https://pypi.org/project/pythonLogs
6
+ Project-URL: Repository, https://github.com/ddc/pythonLogs
7
+ Author-email: Daniel Costa <danieldcsta@gmail.com>
8
+ Maintainer: Daniel Costa
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: log,log-utils,logger,logging,logutils,python,python-3,python3,pythonLogs
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Environment :: Other Environment
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Natural Language :: English
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.12
24
+ Requires-Dist: pydantic-settings>=2.12.0
25
+ Provides-Extra: test
26
+ Requires-Dist: poethepoet>=0.40.0; extra == 'test'
27
+ Requires-Dist: psutil>=7.2.1; extra == 'test'
28
+ Requires-Dist: pytest-cov>=7.0.0; extra == 'test'
29
+ Requires-Dist: pytest>=9.0.2; extra == 'test'
30
+ Description-Content-Type: text/markdown
31
+
32
+ <h1 align="center">
33
+ <img src="https://raw.githubusercontent.com/ddc/pythonLogs/main/assets/pythonLogs-icon.svg" alt="pythonLogs" width="150">
34
+ <br>
35
+ pythonLogs
36
+ </h1>
37
+
38
+ <p align="center">
39
+ <a href="https://www.paypal.com/ncp/payment/6G9Z78QHUD4RJ"><img src="https://img.shields.io/badge/Donate-PayPal-brightgreen.svg?style=plastic" alt="Donate"/></a>
40
+ <a href="https://github.com/sponsors/ddc"><img src="https://img.shields.io/static/v1?style=plastic&label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=ff69b4" alt="Sponsor"/></a>
41
+ <br>
42
+ <a href="https://github.com/astral-sh/uv"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json?style=plastic" alt="uv"/></a>
43
+ <a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json?style=plastic" alt="Ruff"/></a>
44
+ <a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg?style=plastic" alt="Code style: black"/></a>
45
+ <br>
46
+ <a href="https://www.python.org/downloads"><img src="https://img.shields.io/pypi/pyversions/pythonLogs.svg?style=plastic&logo=python&cacheSeconds=3600" alt="Python"/></a>
47
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg?style=plastic" alt="License: MIT"/></a>
48
+ <a href="https://pepy.tech/projects/pythonLogs"><img src="https://static.pepy.tech/badge/pythonLogs?style=plastic" alt="PyPI Downloads"/></a>
49
+ <a href="https://pypi.python.org/pypi/pythonLogs"><img src="https://img.shields.io/pypi/v/pythonLogs.svg?style=plastic&logo=python&cacheSeconds=3600" alt="PyPi"/></a>
50
+ <br>
51
+ <a href="https://github.com/ddc/pythonLogs/issues"><img src="https://img.shields.io/github/issues/ddc/pythonLogs?style=plastic" alt="issues"/></a>
52
+ <a href="https://codecov.io/gh/ddc/pythonLogs"><img src="https://codecov.io/gh/ddc/pythonLogs/graph/badge.svg?token=XWB53034GI&style=plastic" alt="codecov"/></a>
53
+ <a href="https://sonarcloud.io/dashboard?id=ddc_pythonLogs"><img src="https://sonarcloud.io/api/project_badges/measure?project=ddc_pythonLogs&metric=alert_status&style=plastic" alt="Quality Gate Status"/></a>
54
+ <a href="https://github.com/ddc/pythonLogs/actions/workflows/workflow.yml"><img src="https://github.com/ddc/pythonLogs/actions/workflows/workflow.yml/badge.svg?style=plastic" alt="CI/CD Pipeline"/></a>
55
+ <a href="https://actions-badge.atrox.dev/ddc/pythonLogs/goto?ref=main"><img src="https://img.shields.io/endpoint.svg?url=https%3A//actions-badge.atrox.dev/ddc/pythonLogs/badge?ref=main&label=build&logo=none&style=plastic" alt="Build Status"/></a>
56
+ </p>
57
+
58
+ <p align="center">High-performance Python logging library with file rotation and optimized caching for better performance</p>
59
+
60
+
61
+ # Table of Contents
62
+
63
+ - [Features](#features)
64
+ - [Installation](#installation)
65
+ - [Logger Types](#logger-types)
66
+ - [Basic Logger](#basic-logger)
67
+ - [Size Rotating Logger](#size-rotating-logger)
68
+ - [Timed Rotating Logger](#timed-rotating-logger)
69
+ - [Context Manager Support](#context-manager-support)
70
+ - [Using With Multiple Log Levels and Files](#using-with-multiple-log-levels-and-files)
71
+ - [Environment Variables](#env-variables-optional)
72
+ - [Flexible Configuration Options](#flexible-configuration-options)
73
+ - [Development](#development)
74
+ - [Create DEV Environment, Running Tests and Building Wheel](#create-dev-environment-running-tests-and-building-wheel)
75
+ - [Optionals](#optionals)
76
+ - [License](#license)
77
+ - [Support](#support)
78
+
79
+
80
+
81
+ # Features
82
+
83
+ ✨ **Factory Pattern** - Easy logger creation with centralized configuration
84
+ 🚀 **High Performance** - Optimized caching for 90%+ performance improvements
85
+ 🔄 **File Rotation** - Automatic rotation by size or time with compression
86
+ 🎯 **Type Safety** - Enum-based configuration with IDE support
87
+ ⚙️ **Flexible Configuration** - Environment variables, direct parameters, or defaults
88
+ 📍 **Location Tracking** - Optional filename and line number in logs
89
+ 🌍 **Timezone Support** - Full timezone handling including `localtime` and `UTC`
90
+ 💾 **Memory Efficient** - Logger registry and settings caching
91
+ 🔒 **Context Manager Support** - Automatic resource cleanup and exception safety
92
+ 🧵 **Thread Safe** - Concurrent access protection for all operations
93
+ 🔧 **Resource Management** - Automatic handler cleanup and memory leak prevention
94
+
95
+
96
+ # Installation
97
+
98
+ ```shell
99
+ pip install pythonLogs
100
+ ```
101
+
102
+
103
+ # Logger Types
104
+
105
+ > **Tip:** All logger types support both string values (e.g., `level="debug"`) and type-safe enums (e.g., `level=LogLevel.DEBUG`). \
106
+ > See [Flexible Configuration Options](#flexible-configuration-options) for all available enums.
107
+
108
+ ## Basic Logger
109
+
110
+ Console-only logging without file output. Perfect for development and simple applications.
111
+
112
+ ### Usage
113
+
114
+ ```python
115
+ from pythonLogs import BasicLog
116
+
117
+ logger = BasicLog(
118
+ name="my_app",
119
+ level="debug", # "debug", "info", "warning", "error", "critical"
120
+ timezone="America/Sao_Paulo",
121
+ showlocation=False
122
+ )
123
+ logger.warning("This is a warning example")
124
+ ```
125
+
126
+ ### Example Output
127
+
128
+ `[2024-10-08T19:08:56.918-0300]:[WARNING]:[my_app]:This is a warning example`
129
+
130
+
131
+
132
+
133
+
134
+ ## Size Rotating Logger
135
+
136
+ File-based logging with automatic rotation when files reach a specified size. Rotated files are compressed as `.gz`.
137
+
138
+ - **Rotation**: Based on file size (`maxmbytes` parameter)
139
+ - **Naming**: Rotated logs have sequence numbers: `app.log_1.gz`, `app.log_2.gz`
140
+ - **Cleanup**: Old logs deleted based on `daystokeep` (default: 30 days)
141
+
142
+ ### Usage
143
+
144
+ ```python
145
+ from pythonLogs import SizeRotatingLog
146
+
147
+ logger = SizeRotatingLog(
148
+ name="my_app",
149
+ level="debug", # "debug", "info", "warning", "error", "critical"
150
+ directory="/app/logs",
151
+ filenames=["main.log", "app1.log"],
152
+ maxmbytes=5,
153
+ daystokeep=7,
154
+ timezone="America/Chicago",
155
+ streamhandler=True,
156
+ showlocation=False
157
+ )
158
+ logger.warning("This is a warning example")
159
+ ```
160
+
161
+ ### Example Output
162
+
163
+ `[2024-10-08T19:08:56.918-0500]:[WARNING]:[my_app]:This is a warning example`
164
+
165
+
166
+
167
+
168
+
169
+ ## Timed Rotating Logger
170
+
171
+ File-based logging with automatic rotation based on time intervals. Rotated files are compressed as `.gz`.
172
+
173
+ - **Rotation**: Based on time (`when` parameter, defaults to `midnight`)
174
+ - **Naming**: Rotated logs have date suffix: `app_20240816.log.gz`
175
+ - **Cleanup**: Old logs deleted based on `daystokeep` (default: 30 days)
176
+ - **Supported Intervals**: `midnight`, `hourly`, `daily`, `W0-W6` (weekdays, 0=Monday)
177
+
178
+ ### Usage
179
+
180
+ ```python
181
+ from pythonLogs import TimedRotatingLog
182
+
183
+ logger = TimedRotatingLog(
184
+ name="my_app",
185
+ level="debug", # "debug", "info", "warning", "error", "critical"
186
+ directory="/app/logs",
187
+ filenames=["main.log", "app2.log"],
188
+ when="midnight", # "midnight", "H", "D", "W0"-"W6"
189
+ daystokeep=7,
190
+ timezone="UTC",
191
+ streamhandler=True,
192
+ showlocation=False
193
+ )
194
+ logger.warning("This is a warning example")
195
+ ```
196
+
197
+ ### Example Output
198
+
199
+ `[2024-10-08T19:08:56.918-0000]:[WARNING]:[my_app]:This is a warning example`
200
+
201
+
202
+
203
+
204
+
205
+ # Context Manager Support
206
+
207
+ All logger types support context managers for automatic resource cleanup and exception safety.
208
+
209
+ ## Usage Examples
210
+
211
+ ```python
212
+ from pythonLogs import LogLevel
213
+ from pythonLogs.basic_log import BasicLog
214
+ from pythonLogs.size_rotating import SizeRotatingLog
215
+ from pythonLogs.timed_rotating import TimedRotatingLog
216
+
217
+ # Automatic cleanup with context managers
218
+ with BasicLog(name="app", level=LogLevel.INFO) as logger:
219
+ logger.info("This is automatically cleaned up")
220
+ # Handlers are automatically closed on exit
221
+
222
+ with SizeRotatingLog(name="app", directory="/logs", filenames=["app.log"]) as logger:
223
+ logger.info("File handlers cleaned up automatically")
224
+ # File handlers closed and resources freed
225
+
226
+ # Exception safety - cleanup happens even if exceptions occur
227
+ try:
228
+ with TimedRotatingLog(name="app", directory="/logs") as logger:
229
+ logger.error("Error occurred")
230
+ raise ValueError("Something went wrong")
231
+ except ValueError:
232
+ pass # Logger was still cleaned up properly
233
+ ```
234
+
235
+
236
+
237
+
238
+
239
+ # Using With Multiple Log Levels and Files
240
+
241
+ ```python
242
+ from pythonLogs import SizeRotatingLog, TimedRotatingLog, LogLevel, RotateWhen
243
+
244
+ # Application logger
245
+ app_logger = SizeRotatingLog(
246
+ name="production_app",
247
+ directory="/var/log/myapp",
248
+ filenames=["app.log"],
249
+ maxmbytes=50, # 50MB files
250
+ daystokeep=30, # Keep 30 days
251
+ level=LogLevel.INFO,
252
+ streamhandler=True, # Also log to console
253
+ showlocation=True, # Show file:function:line
254
+ timezone="UTC"
255
+ )
256
+
257
+ # Error logger with longer retention
258
+ error_logger = SizeRotatingLog(
259
+ name="production_errors",
260
+ directory="/var/log/myapp",
261
+ filenames=["errors.log"],
262
+ maxmbytes=10,
263
+ daystokeep=90, # Keep errors longer
264
+ level=LogLevel.ERROR,
265
+ streamhandler=False
266
+ )
267
+
268
+ # Audit logger with daily rotation
269
+ audit_logger = TimedRotatingLog(
270
+ name="audit_log",
271
+ directory="/var/log/myapp",
272
+ filenames=["audit.log"],
273
+ when=RotateWhen.MIDNIGHT,
274
+ level=LogLevel.INFO
275
+ )
276
+
277
+ # Use the loggers
278
+ app_logger.info("Application started")
279
+ error_logger.error("Database connection failed")
280
+ audit_logger.info("User admin logged in")
281
+ ```
282
+
283
+
284
+
285
+
286
+ # Env Variables (Optional)
287
+
288
+ The .env variables file can be used by leaving all options blank when calling the class.\
289
+ If not specified inside the .env file, it will use the default value.\
290
+ This is a good approach for production environments, since options can be changed easily.
291
+ ```python
292
+ from pythonLogs import TimedRotatingLog
293
+ log = TimedRotatingLog()
294
+ ```
295
+
296
+ ```
297
+ LOG_LEVEL=DEBUG
298
+ LOG_TIMEZONE=UTC
299
+ LOG_ENCODING=UTF-8
300
+ LOG_APPNAME=app
301
+ LOG_FILENAME=app.log
302
+ LOG_DIRECTORY=/app/logs
303
+ LOG_DAYS_TO_KEEP=30
304
+ LOG_DATE_FORMAT=%Y-%m-%dT%H:%M:%S
305
+ LOG_STREAM_HANDLER=True
306
+ LOG_SHOW_LOCATION=False
307
+ LOG_MAX_LOGGERS=50
308
+ LOG_LOGGER_TTL_SECONDS=1800
309
+
310
+ # SizeRotatingLog
311
+ LOG_MAX_FILE_SIZE_MB=10
312
+
313
+ # TimedRotatingLog
314
+ LOG_ROTATE_WHEN=midnight
315
+ LOG_ROTATE_AT_UTC=True
316
+ LOG_ROTATE_FILE_SUFIX="%Y%m%d"
317
+ ```
318
+
319
+
320
+
321
+
322
+
323
+
324
+ # Flexible Configuration Options
325
+
326
+ You can use either enums (for type safety) or strings (for simplicity):
327
+
328
+ ```python
329
+ from pythonLogs import LogLevel, RotateWhen
330
+
331
+ # Option 1: Type-safe enums (recommended)
332
+ LogLevel.DEBUG # "DEBUG"
333
+ LogLevel.INFO # "INFO"
334
+ LogLevel.WARNING # "WARNING"
335
+ LogLevel.ERROR # "ERROR"
336
+ LogLevel.CRITICAL # "CRITICAL"
337
+
338
+ # Option 2: String values (case-insensitive)
339
+ "debug" # Same as LogLevel.DEBUG
340
+ "info" # Same as LogLevel.INFO
341
+ "warning" # Same as LogLevel.WARNING
342
+ "warn" # Same as LogLevel.WARN (alias)
343
+ "error" # Same as LogLevel.ERROR
344
+ "critical" # Same as LogLevel.CRITICAL
345
+ "crit" # Same as LogLevel.CRIT (alias)
346
+ # Also supports: "DEBUG", "Info", "Warning", etc.
347
+
348
+ # RotateWhen values
349
+ RotateWhen.MIDNIGHT # "midnight"
350
+ RotateWhen.HOURLY # "H"
351
+ RotateWhen.DAILY # "D"
352
+ RotateWhen.MONDAY # "W0"
353
+ # ... through SUNDAY # "W6"
354
+ # String equivalents: "midnight", "H", "D", "W0"-"W6"
355
+ ```
356
+
357
+
358
+
359
+
360
+
361
+ # Development
362
+
363
+ Must have [UV](https://uv.run/docs/getting-started/installation),
364
+ [Black](https://black.readthedocs.io/en/stable/getting_started.html),
365
+ [Ruff](https://docs.astral.sh/ruff/installation/), and
366
+ [Poe the Poet](https://poethepoet.naber.dev/installation) installed.
367
+
368
+ ## Create DEV Environment, Running Tests and Building Wheel
369
+
370
+ ```shell
371
+ uv sync --all-extras
372
+ poe linter
373
+ poe test
374
+ poe build
375
+ ```
376
+
377
+ ## Optionals
378
+
379
+ ### Create a cprofile.prof file from unit tests
380
+ ```shell
381
+ poe profile
382
+ ```
383
+
384
+
385
+
386
+
387
+
388
+ # License
389
+
390
+ Released under the [MIT License](LICENSE)
391
+
392
+
393
+
394
+
395
+
396
+ # Support
397
+
398
+ If you find this project helpful, consider supporting development:
399
+
400
+ - [GitHub Sponsor](https://github.com/sponsors/ddc)
401
+ - [ko-fi](https://ko-fi.com/ddcsta)
402
+ - [PayPal](https://www.paypal.com/ncp/payment/6G9Z78QHUD4RJ)