Enhanced logging functionality with Rich console output and file rotation
Project description
PowerLogger
A high-performance, thread-safe logging library built with Python's logging module and enhanced with the Rich library for beautiful console output with full UTF-8 support.
โจ Features
- ๐จ Rich Console Output: Beautiful, colored logging with the Rich library
- ๐ Thread-Safe Queue Logging: Asynchronous, non-blocking log processing
- ๐ File Rotation: Automatic log file rotation with size-based truncation
- ๐ UTF-8 Support: Full Unicode and emoji support in log files
- โ๏ธ Configuration Management: Flexible configuration via
log_config.ini - ๐ช Windows Optimized: Special handling for Windows file access issues
- ๐ง Multiple Logger Types: Console-only, file-only, queue-based, and combined loggers
- โก High Performance: Optimized for real-time logging applications
- ๐ก๏ธ Production Ready: Comprehensive error handling and recovery mechanisms
๐ Installation
pip install powerlogger
๐ฏ Quick Start
from powerlogger import get_logger
# Create a basic logger
logger = get_logger("my_app")
# Log messages with beautiful formatting
logger.info("๐ Application started successfully!")
logger.warning("โ ๏ธ This is a warning message")
logger.error("โ An error occurred during execution")
logger.debug("๐ Debug information for developers")
๐ Automated Publishing (Windows)
PowerLogger uses GitHub Actions for automated building, testing, and publishing to PyPI on Windows:
- ๐ Auto-publish: Creates GitHub releases automatically
- ๐ช Windows-optimized testing: Comprehensive Windows compatibility testing
- ๐ฆ Multi-version support: Python 3.11-3.13 compatibility on Windows
- ๐ Security scanning: Automated vulnerability checks on Windows
- ๐ Coverage reporting: Windows-specific code coverage metrics
- โก Performance testing: Windows performance and scalability testing
See GitHub Actions Guide for detailed Windows workflow information.
๐ Logger Types
Basic Logger (Console Only)
from powerlogger import get_logger
logger = get_logger("app_name")
# Beautiful console output with colors and formatting
File Logger with Rotation
from powerlogger import get_logger_with_file_handler
logger = get_logger_with_file_handler("app_name")
# Logs to both console and file with automatic rotation
Queue Logger (Thread-Safe)
from powerlogger import get_logger_with_queue
logger = get_logger_with_queue("app_name")
# Asynchronous logging for high-performance applications
Complete Solution (Queue + File)
from powerlogger import get_logger_with_queue_and_file
logger = get_logger_with_queue_and_file("app_name")
# Best of both worlds: thread-safe + file output + rotation
โ๏ธ Configuration
Create log_config.ini in your project root:
[app]
name = my_app
[logging]
output_mode = both
level = INFO
format = %%(levelname)s %%(name)s - %%(message)s
console_format = %%(levelname)s %%(message)s
logs_dir = logs
max_bytes = 1048576
queue_enabled = true
queue_size = 100
flush_interval = 0.1
Configuration Options
| Option | Description | Default | Example |
|---|---|---|---|
level |
Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) | INFO | DEBUG |
format |
Log message format for files | %(levelname)s %(name)s - %(message)s |
%(asctime)s - %(levelname)s - %(message)s |
console_format |
Log message format for console | %(levelname)s %(message)s |
%(levelname)s: %(message)s |
logs_dir |
Directory for log files | logs |
app_logs |
max_bytes |
Maximum log file size before rotation | 1MB (1048576) | 5242880 (5MB) |
queue_enabled |
Enable thread-safe queue logging | true | false |
queue_size |
Maximum queue size for log records | 100 | 1000 |
flush_interval |
Queue flush interval in seconds | 0.1 | 0.5 |
๐ Log Rotation
PowerLogger automatically manages log file sizes through intelligent truncation:
- Size-based Rotation: Logs rotate when they reach
max_bytes - Truncation Strategy: Current log file is truncated to start fresh
- Single File Management: Maintains one log file instead of multiple backups
- Windows Optimized: Special handling for Windows file access conflicts
๐งต Thread Safety
The queue-based loggers provide enterprise-grade thread safety:
- ๐ Asynchronous Processing: Log records are buffered in a thread-safe queue
- ๐ท Dedicated Worker: Single worker thread processes all log records
- โก Non-blocking: Log emission never blocks your application
- ๐ Configurable: Adjustable queue size and flush intervals
- ๐ก๏ธ Error Handling: Robust error recovery and fallback mechanisms
๐ก Usage Examples
Basic Application Logging
from powerlogger import get_logger
logger = get_logger("my_application")
def main():
logger.info("๐ Starting application")
try:
# Your application logic here
logger.info("โ
Application running successfully")
logger.debug("๐ Processing user input...")
except Exception as e:
logger.error(f"โ Application error: {e}")
logger.exception("๐ Full traceback:")
logger.info("๐ Application finished")
if __name__ == "__main__":
main()
Web Application with File Logging
from powerlogger import get_logger_with_file_handler
import time
logger = get_logger_with_file_handler("web_app")
def handle_request(request_id):
logger.info(f"๐ฅ Processing request {request_id}")
time.sleep(0.1) # Simulate work
logger.info(f"โ
Request {request_id} completed")
# Simulate multiple requests
for i in range(100):
handle_request(i)
High-Performance Multi-threaded Logging
from powerlogger import get_logger_with_queue_and_file
import threading
import time
logger = get_logger_with_queue_and_file("high_perf_app")
def worker(worker_id):
for i in range(1000):
logger.info(f"๐ท Worker {worker_id}: Processing task {i}")
time.sleep(0.001) # Very fast logging
# Start multiple worker threads
threads = []
for i in range(5):
t = threading.Thread(target=worker, args=(i,))
t.start()
threads.append(t)
# Wait for completion
for t in threads:
t.join()
# Clean up resources
from powerlogger import cleanup_loggers
cleanup_loggers()
UTF-8 and Emoji Support
from powerlogger import get_logger_with_file_handler
logger = get_logger_with_file_handler("unicode_test")
# International characters
logger.info("Hola mundo! Bonjour le monde! Hallo Welt!")
logger.warning("Special chars: รก รฉ รญ รณ รบ รฑ รง")
# Emojis and symbols
logger.info("โ
Success! ๐ Launching... ๐ Amazing!")
logger.error("โ Error occurred ๐ฅ Boom! ๐ฅ Fire!")
# Complex Unicode
logger.info("ไธ็ ๐ 2024 ยฉ ยฎ โข")
logger.debug("Math: ยฑ ร รท โ โ โ โค โฅ")
โก Performance Considerations
- ๐ Queue Size: Smaller queues (100-1000) provide better real-time logging
- โฑ๏ธ Flush Interval: Lower intervals (0.1-0.5s) reduce latency but increase CPU usage
- ๐พ File Rotation: Truncation-based rotation minimizes I/O overhead
- ๐งต Thread Count: Single worker thread optimizes resource usage
- ๐ Memory Usage: Efficient memory management for long-running applications
๐ ๏ธ Troubleshooting
Console Colors Not Working
- Windows: Use Windows Terminal or enable ANSI support
- macOS/Linux: Ensure
TERMenvironment variable is set - Check: Verify your terminal supports ANSI color codes
Log Files Not Rotating
- File Size: Ensure file size exceeds
max_bytessetting - Permissions: Check write permissions to the logs directory
- Configuration: Verify
log_config.iniis in the correct location
Queue Performance Issues
- Queue Full: Increase
queue_sizeor reduce logging frequency - High Latency: Decrease
flush_intervalfor faster processing - Memory Usage: Monitor queue size and adjust accordingly
Windows File Access Errors
- Built-in Protection: PowerLogger includes special Windows handling
- File Locks: Ensure no other processes are accessing log files
- Permissions: Run with appropriate user permissions
๐ API Reference
Core Functions
| Function | Description | Returns |
|---|---|---|
get_logger(name, level, config_file) |
Basic Rich console logger | Logger instance |
get_logger_with_file_handler(name, level, log_file, config_file) |
Logger with file output and rotation | Logger instance |
get_logger_with_queue(name, level, config_file) |
Thread-safe queue logger | Logger instance |
get_logger_with_queue_and_file(name, level, log_file, config_file) |
Complete solution | Logger instance |
cleanup_loggers() |
Clean up all loggers and handlers | None |
Utility Functions
| Function | Description | Returns |
|---|---|---|
load_config(config_file) |
Load configuration from INI file | ConfigParser instance |
get_log_level_from_config(config) |
Get log level from config | Logging level constant |
Classes
| Class | Description | Purpose |
|---|---|---|
WindowsSafeRotatingFileHandler |
Windows-optimized file rotation | Handle file rotation safely |
ThreadSafeQueueHandler |
Asynchronous log processing | Process logs in background |
๐งช Testing
Run the test suite to verify everything works:
# Install development dependencies
pip install powerlogger[dev]
# Run tests
python -m pytest tests/ -v
# Run specific test
python -m pytest tests/test_logging.py -v
๐ค Contributing
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests if applicable
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone the repository
git clone https://github.com/Pandiyarajk/powerlogger.git
cd powerlogger
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
# Run tests
python -m pytest tests/ -v
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Changelog
See CHANGELOG.md for a detailed history of changes and features.
๐ What's New in 1.0.0
- ๐ Production Release: First stable release with comprehensive features
- ๐ Truncation-based Rotation: Simplified log rotation strategy
- โก Performance Optimizations: Enhanced queue processing and file handling
- ๐ก๏ธ Windows Compatibility: Improved file access handling for Windows
- ๐ Enhanced Documentation: Comprehensive guides and examples
- ๐งช Test Coverage: Extensive test suite for reliability
- ๐ง Configuration Management: Flexible and robust configuration system
๐ Support
- ๐ง Email: pandiyarajk@live.com
- ๐ Issues: GitHub Issues
- ๐ Documentation: GitHub README
- ๐ฌ Discussions: GitHub Discussions
โญ Star History
If you find PowerLogger useful, please consider giving it a star on GitHub! โญ
Made with โค๏ธ by Pandiyaraj Karuppasamy
PowerLogger - Empowering your applications with beautiful, high-performance logging.
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 powerlogger-0.1.0.tar.gz.
File metadata
- Download URL: powerlogger-0.1.0.tar.gz
- Upload date:
- Size: 39.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c80003b1188ee3574592cd3f1cb9d30f8b3c08bdfa62cb73942399ec3788737c
|
|
| MD5 |
cf819e1414300515f7c976eebf6faccf
|
|
| BLAKE2b-256 |
1fcf32624d95e431d99c931b1e63a179ba89eff4eb0027bbf6cc393530f1cf5c
|
File details
Details for the file powerlogger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: powerlogger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfda96cca146fe347c87c961af3254f849c76660aa919833bbc2ae8003e0a520
|
|
| MD5 |
55eb8521d112c468727177f0e0dba3e1
|
|
| BLAKE2b-256 |
eef4b6b59c54f78e0448f7de9d1fdafe60c0e33a839b9d00f8f4fe13374bc4b4
|