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.
- ๐จ 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
pip install powerlogger
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")
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.
from powerlogger import get_logger
logger = get_logger("app_name")
# Beautiful console output with colors and formatting
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
from powerlogger import get_logger_with_queue
logger = get_logger_with_queue("app_name")
# Asynchronous logging for high-performance applications
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
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
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 |
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
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
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()
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)
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()
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: ยฑ ร รท โ โ โ โค โฅ")
- ๐ 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
- Windows: Use Windows Terminal or enable ANSI support
- macOS/Linux: Ensure
TERM
environment variable is set - Check: Verify your terminal supports ANSI color codes
- File Size: Ensure file size exceeds
max_bytes
setting - Permissions: Check write permissions to the logs directory
- Configuration: Verify
log_config.ini
is in the correct location
- Queue Full: Increase
queue_size
or reduce logging frequency - High Latency: Decrease
flush_interval
for faster processing - Memory Usage: Monitor queue size and adjust accordingly
- Built-in Protection: PowerLogger includes special Windows handling
- File Locks: Ensure no other processes are accessing log files
- Permissions: Run with appropriate user permissions
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 |
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 |
Class | Description | Purpose |
---|---|---|
WindowsSafeRotatingFileHandler |
Windows-optimized file rotation | Handle file rotation safely |
ThreadSafeQueueHandler |
Asynchronous log processing | Process logs in background |
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
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
# 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
This project is licensed under the MIT License - see the LICENSE file for details.
See CHANGELOG.md for a detailed history of changes and features.
- ๐ 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
- ๐ง Email: pandiyarajk@live.com
- ๐ Issues: GitHub Issues
- ๐ Documentation: GitHub README
- ๐ฌ Discussions: GitHub Discussions
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.