Open-source minimal Rich-based logging solution
Project description
OpenLog
A versatile Python logging utility (overengineered python-rich wrapping) designed to enhance logging capabilities with rich console output and optional file logging.
Features
- 🎨 Rich Console Output: Color-coded messages with beautiful formatting
- 📁 Flexible File Logging: Optional file output with session support
- 🔧 Task Management: Progress-bars, special task logging etc.
- 📊 Multiple Log Levels: INFO, ERROR, WARN, and INIT with distinct styling
- 💾 In-Memory Storage: Retrieve and manage logs programmatically
- 🎯 Prefix Support: Add context to your log messages
- 📐 Terminal-Aware: Automatic width detection for optimal formatting
Installation
pip install openlog
Quick Start
Basic Console Logging
from openlog import Logger
logger = Logger()
logger.log("This is an info message")
logger.error("Something went wrong")
logger.warn("This is a warning")
logger.init("System initialized")
Batch Logging
# Add multiple messages
logger.batch.add_message("Processing started")
logger.batch.add_message("Loading configuration")
logger.batch.add_message("Connecting to database")
# Log all messages in the batch
logger.flush_batch()
File Logging
# Basic file logging
file_logger = Logger(write_to_file=True)
file_logger.log("This message goes to console and file")
# Session-based logging (timestamped files)
session_logger = Logger(write_to_file=True, session=True)
session_logger.log("Logged with timestamp in filename")
# Organized in /logs directory
dir_logger = Logger(in_dir=True, write_to_file=True)
dir_logger.log("Logs stored in /logs directory")
Task Management
OpenLog supports tracking long-running tasks with animated progress bars:
logger = Logger()
# Start a task with progress bar
task_id = logger.add_task("Processing large dataset")
# Your long-running code here
# ...
# Stop the task
logger.stop_task(task_id)
Task Management Methods:
- add_task(task_message) - Start a task with progress display
- stop_task(task_id) - Stop a specific task
- get_active_tasks() - Get all currently running tasks
- stop_all_tasks() - Stop all active tasks (useful for cleanup)
Smart Object Formatting
# Simple objects stay inline
logger.log({"user": "Alice", "id": 123})
# Complex objects format vertically
complex_data = {
"users": [
{"id": 1, "name": "Alice", "roles": ["admin", "user"]},
{"id": 2, "name": "Bob", "roles": ["user", "viewer"]},
],
"settings": {
"theme": "dark",
"notifications": {"email": True, "push": False}
}
}
logger.log("User data:")
logger.log(complex_data)
Retrieve Logs Programmatically
# Get recent logs
logs = logger.flush_logs()
# Get all logs from start
all_logs = logger.flush_logs(from_start=True)
Documentation
For detailed information about all features, configuration options, and advanced usage, see FEATURES.md.
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
write_to_file |
bool | False | Enable file logging |
in_dir |
bool | False | Store logs in /logs directory |
session |
bool | False | Create timestamped log files |
prefix |
str | "" | Add prefix to all messages |
Log Levels and Methods
log()- General information (blue)error()- Error messages (red)warn()- Warning messages (yellow)init()- Initialization messages (purple)
Batch Operations
add_to_batch()- Add message to batchflush_batch()- Output all batched messagesclear_batch()- Clear batch without outputbatch_size()- Get number of messages in batch
Task Management
add_task()- Start task with progress barstop_task()- Stop specific taskget_active_tasks()- Get active task informationstop_all_tasks()- Stop all tasks and cleanup
Requirements
- Python 3.9+
- Rich library (automatically installed)
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Links
Project details
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 openlog-2.1.0.tar.gz.
File metadata
- Download URL: openlog-2.1.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c771638e11e1a92bd1e0e01142453387683523ab9074ad3030aff00232e836f
|
|
| MD5 |
03f7cb039c4def64dd267239236d2163
|
|
| BLAKE2b-256 |
4522e1c7916ffb343c2fb490ba316b0da2464d7c578268bea7b49a3d882b06ea
|
File details
Details for the file openlog-2.1.0-py3-none-any.whl.
File metadata
- Download URL: openlog-2.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfb4e139c09fd110e32797caf3a2258b62d5ef18b4b287885abce08e089b5751
|
|
| MD5 |
231304dd7b5f76de22a2ab86f1d2c730
|
|
| BLAKE2b-256 |
68c947eefe4064c0c56eb2d4265577fdef747f28c6f03981be04beba331cb7dd
|