A Python library that augments the standard logging module
Project description
logenrich v1.0.0
A Python library that augments the standard
loggingmodule with simplified, INI-driven configuration.
Prerequisites
- Python
>=3.14
Installation
pip install logenrich
Usage
Import setup_logger directly from the logenrich package:
from logenrich import setup_logger
logger = setup_logger(__name__)
logger.info("Hello from logenrich!")
setup_logger searches upward from the current working directory for a logging.ini file and caches the resolved path for subsequent calls. If no configuration file is found, it falls back to basicConfig at INFO level.
Optional parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
(required) | Logger name, typically __name__. |
conf_dir |
`str | None` | Current working directory |
log_ini |
`str | None` | "logging.ini" |
Architecture
flowchart TD
A[caller: setup_logger] --> B{cache valid?}
B -- yes --> E[getLogger]
B -- no --> C[_find_logging_ini\nwalk up tree]
C --> D{logging.ini\nfound?}
D -- yes --> F[fileConfig\nload INI]
D -- no --> G[basicConfig\nINFO level]
F --> E
G --> E
E --> H[Logger instance]
Configuration
Place a logging.ini file in your project root. The bundled default configures two handlers:
| Handler | Target | Format |
|---|---|---|
| Console | sys.stderr |
%(asctime)s - %(name)s - %(levelname)s - %(message)s |
| File | logenrich.log |
%(asctime)s [%(levelname)s] %(name)s - %(message)s |
Example logging.ini:
[loggers]
keys=root
[handlers]
keys=consoleHandler,fileHandler
[formatters]
keys=logFormatter,consoleFormatter
[logger_root]
level=INFO
handlers=consoleHandler,fileHandler
[handler_consoleHandler]
class=StreamHandler
formatter=consoleFormatter
args=(sys.stderr,)
[handler_fileHandler]
class=FileHandler
formatter=logFormatter
args=('logenrich.log', 'a')
[formatter_logFormatter]
format=%(asctime)s [%(levelname)s] %(name)s - %(message)s
[formatter_consoleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
Development
Requires Poetry
2.2.
Setup
poetry install
Running Tests
poetry run pytest --cov=logenrich tests --cov-report html
Formatting and Linting
poetry run black logenrich; poetry run pylint logenrich
Pylint must score 10/10. Minimum test coverage is 80%.
Publishing to PyPI
Prerequisites
- A PyPI account with an API token.
Configure the token
poetry config pypi-token.pypi <your-token>
Build and publish
poetry publish --build
This builds the source distribution and wheel, then uploads them to PyPI in one step.
Note: PyPI releases are immutable. Once a version is published, it cannot be overwritten.
To fix a mistake, yank the release via the PyPI web UI and publish a new version.
Changelog
See CHANGELOG.md for the full version history.
License
MIT
Author
Ronaldo Webb <ron@ronella.xyz>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logenrich-1.0.0.tar.gz.
File metadata
- Download URL: logenrich-1.0.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.14.4 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c7975b50d28a7ada905a230ba7bd453ee11a20691eeeaa920a5435e4b0dfcd7
|
|
| MD5 |
10a86f0f1c1f31e4689d38e8f6fe5585
|
|
| BLAKE2b-256 |
2a09e939151c1012e4ae578554b3c86b19285d2cfd2b94790ad42dc28c62a15a
|
File details
Details for the file logenrich-1.0.0-py3-none-any.whl.
File metadata
- Download URL: logenrich-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.14.4 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
933816faa73bac9daf583c4b0c7d30ef1416d4872f0566d6a4447c1a9fd9bbc6
|
|
| MD5 |
b7e78d48a4980a65fe71a870c2fba7f1
|
|
| BLAKE2b-256 |
d9555704e1ffb2efa4eb07f0dd0d440915120291b6cf4a9a26bcd1a3c7bc1772
|