Decorative Logger - A logging utility with emoji decorations
Project description
decologr - Decorative Logger
A single file logging utility with emoji decorations and structured message formatting.
setup_logging(verbose=True, project_name="myproject")
╭─────────── myproject ────────────╮
│ myproject Application Starting │
╰──────────────────────────────────╯
[...] INFO ℹ️ myproject starting up with log file
.../.myproject/logs/myproject-...
Features
- Emoji Decorations: Automatic emoji decorations based on log level and message content
- Rich Console Formatting: Beautiful, color-coded console output with syntax highlighting (optional)
- Structured Logging: Support for JSON, parameters, and formatted messages
- Project-Aware: Configurable project name for log file naming
- Backward Compatible: Static method interface for easy migration
Installation
pip install decologr
Optional: Rich Support
For enhanced console output with colors and syntax highlighting:
pip install decologr[rich]
Optional: Textual Support
For interactive log viewing in editors like JDXI:
pip install decologr[textual]
Or install from source:
cd decologr
pip install -e .
Quick Start
from decologr import Decologr, set_project_name, setup_logging
# Set project name (optional, defaults to "decologr")
set_project_name("myproject")
# Setup logging (optional)
setup_logging(verbose=True, project_name="myproject")
# Use Logger
Decologr.info("Hello, world!")
Decologr.error("Something went wrong", exception=ValueError("test"))
Decologr.json({"key": "value"})
Usage
Basic Logging
from decologr import Decologr
Decologr.info("Information message")
Decologr.warning("Warning message")
Decologr.error("Error message")
Decologr.debug("Debug message")
Logging with Exceptions
from decologr import Decologr
try:
result = 1 / 0
except ZeroDivisionError as e:
Decologr.error("Division failed", exception=e)
# With Rich installed, exceptions display with beautiful tracebacks
try:
result = 1 / 0
except ZeroDivisionError as e:
Decologr.error("Division failed", exception=e, use_rich_traceback=True)
# Using log_exception helper function
from decologr import log_exception
try:
# some code
except Exception as ex:
log_exception(ex, "Error initializing database", use_rich_traceback=True)
Rich Traceback Features (when Rich is installed):
- Syntax-highlighted code: Code snippets in tracebacks are syntax-highlighted
- Clear file paths: File paths and line numbers are clearly marked
- Better visualization: Improved formatting for stack frames
- Compact file logging: Standard format still logged to files
JSON Logging
from decologr import Decologr
data = {"user": "alice", "action": "login"}
Decologr.json(data) # Compact JSON (or pretty if Rich is enabled)
# With Rich installed, enable pretty-printing
Decologr.json(data, pretty=True) # Pretty-printed, syntax-highlighted JSON
# Force compact format
Decologr.json(data, pretty=False) # Always compact JSON
# Auto-detect (uses Rich if available)
Decologr.json(data, pretty=None) # Default behavior
Rich JSON Features (when Rich is installed):
- Pretty-printed formatting with proper indentation
- Syntax highlighting for keys, values, and structure
- Better readability for complex nested data
- Compact JSON still logged to files for efficient storage
Parameter Logging
from decologr import Decologr
Decologr.parameter("User ID", user_id)
Decologr.parameter("Settings", {"theme": "dark", "lang": "en"})
# With Rich installed, dictionaries display as tables
config = {
"database": {"host": "localhost", "port": 5432},
"cache": {"enabled": True, "ttl": 3600}
}
Decologr.parameter("Configuration", config, use_rich=True)
# Lists display as trees (especially nested structures)
users = [
{"id": 1, "name": "Alice", "roles": ["admin"]},
{"id": 2, "name": "Bob", "roles": ["user"]}
]
Decologr.parameter("Users", users, use_rich=True)
Rich Parameter Features (when Rich is installed):
- Tables for dictionaries: Key-value pairs displayed in formatted tables
- Trees for lists: Nested structures displayed as expandable trees
- Better visualization: Color-coded values, proper formatting
- Compact file logging: Still logs compact format to files
Header Messages
from decologr import Decologr
Decologr.header_message("Starting Processing")
# With Rich installed, headers display as formatted panels
Decologr.header_message("Starting Processing", use_rich=True)
# Custom title for Rich panel
Decologr.header_message("Processing Complete", title="[bold green]Success[/bold green]", use_rich=True)
# Different log levels show different border colors
Decologr.header_message("Warning Section", level=logging.WARNING, use_rich=True)
Decologr.header_message("Error Section", level=logging.ERROR, use_rich=True)
Rich Header Features (when Rich is installed):
- Formatted panels: Headers displayed as bordered panels
- Color-coded borders: Border color matches log level (INFO=blue, WARNING=yellow, ERROR=red)
- Custom titles: Optional custom titles for panels
- Better visual hierarchy: Clear separation and distinction
- Text file logging: Still logs separator lines to files
Configuration
Setting Project Name
from decologr import set_project_name, get_project_name
set_project_name("myproject")
print(get_project_name()) # "myproject"
Setup Logging
from decologr import setup_logging
# Setup with default project name
logger = setup_logging()
# Setup with custom project name
logger = setup_logging(project_name="myproject", verbose=True)
# Enable Rich formatting (if Rich is installed)
logger = setup_logging(use_rich=True, project_name="myproject")
# Auto-detect Rich (uses Rich if available, otherwise falls back to plain)
logger = setup_logging(use_rich=None, project_name="myproject")
Rich Integration
When Rich is installed and enabled, decologr provides:
- Color-coded log levels: DEBUG (dim white), INFO (blue), WARNING (yellow), ERROR (red), CRITICAL (bold red)
- Syntax highlighting: Automatic highlighting for code, file paths, and structured data
- Beautiful tracebacks: Enhanced exception display with syntax highlighting
- Markup support: Rich markup in log messages for additional formatting
Rich formatting is optional - decologr works perfectly without it, maintaining full backward compatibility.
Textual Log Viewer
When Textual is installed, decologr provides a beautiful log viewer component that can be integrated into programs like JDXI Editor:
from decologr.viewer import create_log_viewer_widget
from pathlib import Path
# Create a viewer line_edit for embedding in your editor
log_file = Path("~/.decologr/logs/myproject.log")
viewer = create_log_viewer_widget(log_file=log_file)
# Or run standalone viewer
from decologr.viewer import run_log_viewer
run_log_viewer(log_file)
Textual Viewer Features:
- Color-coded log levels: Visual distinction for DEBUG, INFO, WARNING, ERROR, CRITICAL
- Search functionality: Filter logs by text content
- Level filtering: Show only logs above a certain level
- Formatted display: Clean, readable table format
- Auto-scroll: Automatically scrolls to latest logs
- Embeddable: Can be integrated into editors and applications
Standalone Usage:
python -m decologr.viewer <log_file>
# Or use the most recent log file automatically
python -m decologr.viewer
API Reference
Logger Class
All methods are static methods:
Decologr.info(message, *args, level=logging.INFO, stacklevel=3, silent=False)Decologr.debug(message, *args, level=logging.DEBUG, stacklevel=3, silent=False)Decologr.warning(message, *args, exception=None, level=logging.WARNING, stacklevel=4, silent=False, use_rich_traceback=None)- Log warninguse_rich_traceback=True: Use Rich traceback formatting (requires Rich)use_rich_traceback=False: Always use standard tracebackuse_rich_traceback=None: Auto-detect (uses Rich if available)
Decologr.error(message, *args, exception=None, level=logging.ERROR, stacklevel=4, silent=False, use_rich_traceback=None)- Log erroruse_rich_traceback=True: Use Rich traceback formatting (requires Rich)use_rich_traceback=False: Always use standard tracebackuse_rich_traceback=None: Auto-detect (uses Rich if available)
Decologr.json(data, silent=False, pretty=None)- Log JSON datapretty=True: Use Rich pretty-printing (requires Rich)pretty=False: Always use compact formatpretty=None: Auto-detect (uses Rich if available)
Decologr.parameter(message, parameter, float_precision=2, max_length=300, level=logging.INFO, stacklevel=4, silent=False, use_rich=None)- Log structured parameteruse_rich=True: Use Rich tables/trees (requires Rich)use_rich=False: Always use text-based formattinguse_rich=None: Auto-detect (uses Rich if available)
Decologr.header_message(message, level=logging.INFO, silent=False, stacklevel=3, use_rich=None, title=None)- Log header messageuse_rich=True: Use Rich panel formatting (requires Rich)use_rich=False: Always use text-based separator linesuse_rich=None: Auto-detect (uses Rich if available)title: Optional custom title for Rich panel
Decologr.debug_info(successes, failures, stacklevel=3)
Functions
setup_logging(verbose=False, project_name="decologr", use_rich=None)- Setup logging configurationuse_rich: IfTrue, use Rich formatting (requires Rich to be installed)use_rich: IfNone, auto-detect and use Rich if availableuse_rich: IfFalse, use plain text formatting
log_exception(exception, message, stacklevel=4, use_rich_traceback=None)- Log exception with messageuse_rich_traceback: Control Rich traceback formatting (same as error/warning methods)
cleanup_logging(logger)- Clean up logging handlersset_project_name(project_name)- Set the project name for loggingget_project_name()- Get the current project name
Example Output:
from decologr import Decologr, set_project_name, setup_logging
# Set project name (optional, defaults to "decologr")
set_project_name("myproject")
# Setup logging (optional)
setup_logging(verbose=True, project_name="myproject")
╭─────────── myproject ────────────╮
│ myproject Application Starting │
╰──────────────────────────────────╯
[...] INFO ℹ️ myproject starting up with log file
.../.myproject/logs/myproject-...
<Logger myproject (INFO)>
# Use Logger
Decologr.info("Hello, world!")
INFO ℹ️ Hello, world!
Decologr.error("Something went wrong", exception=ValueError("test"))
{
"key": "value"
}
License
MIT License
Author
Originally part of the JDXi Editor project.
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 decologr-0.3.6.tar.gz.
File metadata
- Download URL: decologr-0.3.6.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25ea986aa4a4787164ea3861ff888fe491297f500250b791daae2cba8003a3e2
|
|
| MD5 |
d185c1f8c8435a35865eafd6ac192925
|
|
| BLAKE2b-256 |
2ce54c28a16a3c9f29b0cac4979fbaec1c4aa2334d1b38e9b472838099226607
|
Provenance
The following attestation bundles were made for decologr-0.3.6.tar.gz:
Publisher:
python-publish.yml on markxbrooks/decologr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
decologr-0.3.6.tar.gz -
Subject digest:
25ea986aa4a4787164ea3861ff888fe491297f500250b791daae2cba8003a3e2 - Sigstore transparency entry: 1030834642
- Sigstore integration time:
-
Permalink:
markxbrooks/decologr@d82d70e4f73310d6480abd52dfd92a4273a29511 -
Branch / Tag:
refs/tags/v0.3.6 - Owner: https://github.com/markxbrooks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d82d70e4f73310d6480abd52dfd92a4273a29511 -
Trigger Event:
release
-
Statement type:
File details
Details for the file decologr-0.3.6-py3-none-any.whl.
File metadata
- Download URL: decologr-0.3.6-py3-none-any.whl
- Upload date:
- Size: 23.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
755f5dbbb35c18a3780326d6b20e13f04677be88c702befd7d0e7902b1b0a78b
|
|
| MD5 |
08869d900759fce1576da1a72725f899
|
|
| BLAKE2b-256 |
89894e1af0ad570d71b3529e1b678e6d9cd25a219c39a50b2a2cb7bb67765086
|
Provenance
The following attestation bundles were made for decologr-0.3.6-py3-none-any.whl:
Publisher:
python-publish.yml on markxbrooks/decologr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
decologr-0.3.6-py3-none-any.whl -
Subject digest:
755f5dbbb35c18a3780326d6b20e13f04677be88c702befd7d0e7902b1b0a78b - Sigstore transparency entry: 1030834715
- Sigstore integration time:
-
Permalink:
markxbrooks/decologr@d82d70e4f73310d6480abd52dfd92a4273a29511 -
Branch / Tag:
refs/tags/v0.3.6 - Owner: https://github.com/markxbrooks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d82d70e4f73310d6480abd52dfd92a4273a29511 -
Trigger Event:
release
-
Statement type: