Skip to main content

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.

PyPI version Python versions License

โœจ 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 TERM environment variable is set
  • Check: Verify your terminal supports ANSI color codes

Log Files Not Rotating

  • 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 Performance Issues

  • 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

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:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests if applicable
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. 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

โญ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

powerlogger-0.1.0.tar.gz (39.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

powerlogger-0.1.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

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

Hashes for powerlogger-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c80003b1188ee3574592cd3f1cb9d30f8b3c08bdfa62cb73942399ec3788737c
MD5 cf819e1414300515f7c976eebf6faccf
BLAKE2b-256 1fcf32624d95e431d99c931b1e63a179ba89eff4eb0027bbf6cc393530f1cf5c

See more details on using hashes here.

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

Hashes for powerlogger-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfda96cca146fe347c87c961af3254f849c76660aa919833bbc2ae8003e0a520
MD5 55eb8521d112c468727177f0e0dba3e1
BLAKE2b-256 eef4b6b59c54f78e0448f7de9d1fdafe60c0e33a839b9d00f8f4fe13374bc4b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page