Colorful console and structured JSON logging for Python.
Project description
Decima
Decima is a robust, custom logging library for Python that enhances your application's observability with colorful console output and structured JSON logging. Designed for clarity and ease of use, it helps developers track down issues faster with a dedicated TRACE level and automatic file management.
Key Features
- 🎨 Colorful Console Output: Instantly distinguish log levels with vibrant color coding (Cyan for TRACE, Blue for DEBUG, Red for ERROR, etc.).
- 📊 Structured JSON Logging: Automatically writes logs to
.jsonlfiles, perfect for ingestion by log analysis tools. - 🔍 Custom TRACE Level: Includes a
TRACE(level 5) severity for ultra-granular debugging, below the standardDEBUG. - 📁 Automated File Management: seamlessly handles log file creation, including timestamped run logs and cumulative JSON logs.
- ⚡ Simple Configuration: Get up and running with a single static setup call.
Installation
Decima is distributed on PyPI as decimalog:
# Using pip
pip install decimalog
# Using uv
uv add decimalog
The import package remains decima:
from decima import CustomLogger
Usage
Integrating Decima into your project is straightforward.
1. Setup Logging
Initialize the logger at the start of your application entry point:
import logging
from decima import CustomLogger
# Configure logging:
# - folder: Directory to store log files
# - filename: Base name for log files
# - level: Minimum logging level (e.g., "DEBUG", "INFO")
# - class_length: Max length for logger name in console output (for alignment)
CustomLogger.setup_logging(
folder="logs",
filename="app",
level="DEBUG",
class_length=20
)
# Get a logger instance
logger = logging.getLogger("MyApp")
2. Logging Messages
You can now use the standard logging methods, plus the new trace method (if using CustomLogger explicitly or if the level is registered):
logger.info("Application started successfully.")
logger.warning("Configuration file missing, using defaults.")
logger.error("Failed to connect to database.")
# For Trace level (level 5)
# Note: Ensure usage complies with the CustomLogger class capabilities
custom_logger = logging.getLogger("MyApp")
if isinstance(custom_logger, CustomLogger):
custom_logger.trace("Entering complex calculation loop...")
To fully utilize the trace method with type safety, you might want to ensure your logger is typed as CustomLogger.
Output Formats
Console Output:
2023-10-27 10:00:00,123 - [INFO] - MyApp - Application started successfully.
(With appropriate colors applied)
JSON Output (logs/app.jsonl):
{"timestamp": "2023-10-27T10:00:00.123456-05:00", "level": "INFO", "name": "MyApp", "message": "Application started successfully."}
specific Configuration
LogFormatter: Handles the colorization and formatting of console logs.JsonFormatter: Handles the serialization of log records into JSON structure.class_length: Truncates the logger name in the console output to keep columns aligned, preserving the end of the name.
Development
This project uses uv for dependency management and hatch for building.
Setting up the environment
uv sync --all-extras --dev
Running Tests
uv run pytest
Linting & Formatting
uv run ruff check .
uv run ruff format .
Building Documentation
Decima uses mkdocs for documentation.
uv run mkdocs serve
License
This project is licensed under the MIT License. See the LICENSE file for details.
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 decimalog-0.2.1.tar.gz.
File metadata
- Download URL: decimalog-0.2.1.tar.gz
- Upload date:
- Size: 39.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ca33868416dc8cc87c2f4a43d5f70b0aa6a70ae9d7e432352818b91020bc394
|
|
| MD5 |
61a117724ca6c14d58dfe819fd7f4582
|
|
| BLAKE2b-256 |
55adf894a7147bc7520c27d5e8625367738bd8c0d6d493adab895b8505e621d2
|
File details
Details for the file decimalog-0.2.1-py3-none-any.whl.
File metadata
- Download URL: decimalog-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7da6cef1437d8e16f43ee0aa83f8bcae267615f7a7715a77cbabec9bde311582
|
|
| MD5 |
3e9c930428a6ed82602f15a9c8bea134
|
|
| BLAKE2b-256 |
1e0a147e673d225cb54bab705f297278c3e6b4329d4121d5c8c27fca882d8d1e
|