Logging Utilities
A small Python utility for adding custom logging levels to Python's standard logging module.
add_new_level() registers a level name and numeric value, adds a matching constant to logging, and adds a lowercase logging method to logging.Logger. For example, registering TRACE creates logging.TRACE and allows calls such as logger.trace("message").
Features
- Validates custom level names and numeric values.
- Rejects names, logger methods, and numeric levels that are already in use.
- Uses the standard logger machinery, supporting message arguments and options such as
extra,exc_info,stack_info, andstacklevel. - Includes
configure_logging()as a convenience configuration for applications that want aTRACElevel and a standard log format.
Requirements
- Python 3.12 or later.
Usage
Register a custom level before using it:
import logging
from logging_config import add_new_level
add_new_level("TRACE", 15)
logging.basicConfig(
level=logging.TRACE,
format="%(asctime)s %(levelname)-8s %(name)s: %(message)s",
)
logger = logging.getLogger(__name__)
logger.trace("Reading configuration for %s", "my_app")
logger.info("Application started")
The level name must be a non-empty uppercase string. The level number must be a positive integer (not a Boolean). Registration raises ValueError when the name, corresponding logger method, or numeric level conflicts with an existing logging entry.
Default configuration
Call configure_logging() once during application startup to register TRACE at level 15 and configure basic logging with an INFO threshold:
from logging_config import configure_logging
configure_logging()
The default INFO threshold filters out TRACE messages because TRACE (15) is less severe than INFO (20). To see TRACE messages, configure logging with a threshold of logging.TRACE or another value no greater than 15. configure_logging() registers TRACE each time it is called, so call it only once per process.
Development setup
Create a virtual environment from the repository root. For Windows with Python 3.12:
py -3.12 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
The requirements file installs the project's current test and lint tools.
Run tests
python -m pytest
Run the test suite with coverage and print the report:
coverage run -m pytest
coverage report
Run Ruff
Check the source module for lint issues and formatting:
ruff check src/logging_config.py
ruff format --check src/logging_config.py
To apply Ruff's automatic fixes, run ruff check --fix src/logging_config.py, then rerun the tests and checks.
Project layout
logging/
├── .github/workflows/ # GitHub Actions for Ruff, tests/coverage, and PyPI publishing
├── src/
│ └── logging_config.py
├── tests/
│ └── test_logging_config.py
├── LICENSE
├── README.md
├── pyproject.toml # Project metadata and tool configuration
└── requirements.txt # Development/test tools
Continuous integration
The GitHub Actions workflows are configured to run Ruff checks and pytest with coverage on pushes and pull requests. A separate workflow builds distributions and attempts to publish them to PyPI when a version tag matching v* is pushed. The PyPI workflow still contains a placeholder project URL and requires project-specific release configuration before publishing.
Packaging status
Ready for packaging using the Github packaging action.
License
This project is licensed under the MIT License. See `[LICENSE] for details.
Metadata
Release files for Logging-utils-dnc 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| logging_utils_dnc-0.0.1.tar.gz | 6.5 kB | With provenance | Details for logging_utils_dnc-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| logging_utils_dnc-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for logging_utils_dnc-0.0.1-py3-none-any.whl |
Total release size: 12.1 kB
Release files / logging_utils_dnc-0.0.1.tar.gz
| Download URL | logging_utils_dnc-0.0.1.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba187903ab184db5de4b9f64aee5930e23c41c25647d74510644157940ca4267
|
|
BLAKE2b-256 checksum How to use checksums |
cb4db82a89af41f5888d3bbdc4257a35aad95455b15894585b1d561ca880b67b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logRelease files / logging_utils_dnc-0.0.1-py3-none-any.whl
| Download URL | logging_utils_dnc-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59eb0ca0a3c398a3383b160eeefc1d1374ea18348f9608ab7eccea7fd6b0420a
|
|
BLAKE2b-256 checksum How to use checksums |
3ec3b140e08359c31fafc4982fd02575736080a66d722a2e7b548f693db4d37d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logSecurity for Logging-utils-dnc 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for logging_utils_dnc-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.