A flexible logging system with file, console, and GUI (PySide6) output options
Project description
Modern Logger
A high-performance, flexible logging system with file, console, and GUI output options designed for modern Python applications.
โจ Features
- ๐ High Performance: Optimized for minimal overhead and efficient memory usage
- ๐ฏ Multiple Output Options: Log to files, console, GUI, or any combination
- ๐ Smart File Logging: Automatic file creation and intelligent directory handling
- ๐จ Colorful Console: Rich console output with customizable colors using colorama
- ๐ฅ๏ธ Modern GUI (PySide6): Advanced Qt-based interface with progress indicators, scroll management, and real-time updates
- ๐ Multi-Logger: Send logs to multiple destinations simultaneously with intelligent routing
- โก Lazy Loading: PySide6 only imported when GUI functionality is requested
- ๐ฆ Optional Dependencies: Full CLI functionality without installing GUI dependencies (PySide6)
- ๐ Advanced Export: Export logs in multiple formats (LOG, CSV, XML, JSON) with filtering and metadata
- ๐งต Thread-Safe: Fully thread-safe for multithreaded applications
- ๐พ Memory Management: Automatic memory management for long-running applications
๐๏ธ Project Structure
ModernLogger/
โโโ modern_logger/ # Core package
โ โโโ __init__.py # Package initialization with lazy loading
โ โโโ logger.py # Base logger with export functionality
โ โโโ gui_logger.py # Advanced GUI logger components
โ โโโ gui_adapter.py # GUI-logger integration adapter
โโโ examples/ # 18 comprehensive examples
โ โโโ 01_basic_logging/ # Simple console logging
โ โโโ 02_file_logging/ # File logging with dual output
โ โโโ 03_console_colors/ # Custom console colors
โ โโโ 04_multi_logger/ # Multiple logger routing
โ โโโ 05_log_levels/ # Log level filtering
โ โโโ 06_export_log/ # Standard .log export
โ โโโ 07_export_csv/ # CSV format export
โ โโโ 08_export_xml/ # XML format export
โ โโโ 09_export_json/ # JSON format export
โ โโโ 10_gui_logging/ # Basic GUI integration
โ โโโ 11_level_filtering/ # Advanced filtering
โ โโโ 12_memory_management/ # Memory optimization
โ โโโ 13_gui_queue_mode/ # GUI message queuing
โ โโโ 14_gui_inline_mode/ # Real-time progress updates
โ โโโ 15_gui_non_queue_mode/ # Immediate message display
โ โโโ 16_gui_multithread/ # Thread-safe GUI logging
โ โโโ 17_gui_progress_tracking/ # Advanced progress monitoring
โ โโโ 18_gui_scroll_management/ # Intelligent scroll behavior
โ โโโ cli_example.py # Command-line application demo
โ โโโ gui_example.py # Comprehensive GUI demo
โ โโโ export_example.py # Export functionality demo
โ โโโ README.md # Complete examples documentation
โโโ logs/ # Generated log files
โโโ exports/ # Exported log files
โโโ .venv/ # Python virtual environment
โโโ install.py # Automated installation script
โโโ setup.py # Package configuration
โโโ pyproject.toml # Modern Python packaging
โโโ LICENSE # MIT license
โโโ README.md # This file
๐ Installation
Automated Installation (Recommended)
# Full installation with GUI support (includes PySide6)
python install.py
# Development installation (editable)
python install.py --dev
# CLI-only installation (no PySide6/GUI dependencies)
python install.py --no-gui
Manual Installation
# Install from PyPI (CLI-only, no PySide6)
pip install modern-logger
# Install with GUI support (includes PySide6)
pip install modern-logger[gui]
# Install PySide6 separately if needed
pip install PySide6>=6.0.0
# Install from source
git clone https://github.com/yourusername/modern-logger.git
cd modern-logger
pip install -e .[gui] # With GUI support (PySide6)
# or
pip install -e . # CLI-only (no PySide6)
๐ Quick Start
Basic Logging
from modern_logger import ModernLogger
# Simple console logging
logger = ModernLogger()
logger.info("Application started")
logger.warning("This is a warning")
logger.error("An error occurred")
File Logging
# Log to file with automatic directory creation
logger = ModernLogger(file="logs/app.log")
logger.info("This will be written to the file")
# Both console and file
logger = ModernLogger(console=True, file="logs/app.log")
logger.info("This goes to both console and file")
GUI Logging (Requires PySide6)
# Modern GUI with advanced features (requires PySide6)
logger = ModernLogger(gui=True)
widget = logger.get_gui_widget()
# Add to your application layout
# layout.addWidget(widget)
logger.info("This appears in the GUI logger")
# Advanced GUI features
gui_widget = logger.get_gui_widget()
gui_widget.set_loading_on(queue_messages=True)
logger.info("This message will be queued")
gui_widget.set_loading_off("Operation completed!")
Note: GUI functionality requires PySide6. Install with
pip install modern-logger[gui]orpip install PySide6>=6.0.0
๐ง Advanced Usage
Multi-Logger Configuration
from modern_logger import Logger, FileLogger, ConsoleLogger, MultiLogger
# Create specialized loggers
console = ConsoleLogger(level=Logger.DEBUG)
file_log = FileLogger("app.log", level=Logger.INFO)
# Combine multiple destinations
multi = MultiLogger(loggers=[console, file_log])
multi.info("Goes to both console and file")
Log Export & Analysis
# Generate comprehensive logs
logger = ModernLogger()
logger.info("Application started")
logger.warning("High memory usage")
logger.error("Connection failed")
logger.critical("System overload")
# Export in multiple formats
logger.export_log("logs/all.json", "json") # All logs as JSON
logger.export_log("logs/errors.csv", "csv", level_filter=Logger.ERROR) # Errors only
logger.export_log("logs/recent.xml", "xml", limit=10) # Last 10 logs
logger.export_log("logs/warnings.log", "log", level_filter=Logger.WARNING) # Warnings+
Thread-Safe GUI Logging
import threading
from modern_logger import ModernLogger
logger = ModernLogger(gui=True)
def worker_function(worker_id):
for i in range(10):
logger.info(f"Worker {worker_id}: Processing item {i}")
time.sleep(0.1)
# Start multiple threads safely
threads = []
for i in range(4):
thread = threading.Thread(target=worker_function, args=(i,))
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
๐จ GUI Features
The ModernLogger GUI provides advanced features for real-time monitoring:
Queue Mode - Batch Processing
gui_widget.set_loading_on(queue_messages=True)
# Messages are queued during loading
logger.info("Processing item 1...")
logger.info("Processing item 2...")
gui_widget.set_loading_off("All items processed!") # Messages appear at once
Inline Mode - Real-time Progress
gui_widget.set_loading_on(queue_messages=False, passthrough_messages=True, inline_update=True)
for i in range(1, 101):
gui_widget.update_progress(i, 100, f"Processing {i}%")
time.sleep(0.1)
gui_widget.set_loading_off("Processing complete!")
Non-Queue Mode - Immediate Display
gui_widget.set_loading_on(queue_messages=False, passthrough_messages=True)
# Messages appear immediately as they're sent
logger.info("Real-time message 1")
logger.info("Real-time message 2")
Smart Scroll Management
- Auto-scroll: Automatically follows new messages when at bottom
- Scroll Button: Convenient scroll-to-bottom button with centered arrow
- Position Memory: Preserves scroll position during operations
- High Volume: Handles rapid message streams smoothly
๐ Export Formats
LOG Format (.log)
[2025-05-28 14:56:50] [INFO] Application started
[2025-05-28 14:56:50] [WARNING] High memory usage detected
[2025-05-28 14:56:50] [ERROR] Connection failed
CSV Format (.csv)
Timestamp,Level,Level_Name,Logger_Name,Message
2025-05-28T14:56:50.123456,20,INFO,MultiLogger,Application started
2025-05-28T14:56:50.234567,30,WARNING,MultiLogger,High memory usage
XML Format (.xml)
<?xml version='1.0' encoding='utf-8'?>
<logs exported_at="2025-05-28T14:56:51.000000" total_records="3">
<log>
<timestamp>2025-05-28T14:56:50.123456</timestamp>
<level>20</level>
<level_name>INFO</level_name>
<logger_name>MultiLogger</logger_name>
<message>Application started</message>
</log>
</logs>
JSON Format (.json)
{
"metadata": {
"exported_at": "2025-05-28T14:56:51.000000",
"total_records": 3,
"logger_name": "MultiLogger"
},
"logs": [
{
"timestamp": "2025-05-28T14:56:50.123456",
"level": 20,
"level_name": "INFO",
"message": "Application started",
"logger_name": "MultiLogger"
}
]
}
๐ง Export Options
- format_type:
"log","csv","xml", or"json" - level_filter: Export only specific levels (
Logger.DEBUG,Logger.INFO,Logger.WARNING,Logger.ERROR,Logger.CRITICAL) - limit: Maximum number of records (most recent logs)
๐ Examples
The project includes 18 comprehensive examples in the examples/ directory:
Foundational Examples (01-05)
- Basic logging, file logging, console colors, multi-logger, log levels
Export Examples (06-09)
- Export to .log, .csv, .xml, .json with filtering and metadata
Advanced Examples (10-12)
- GUI integration, level filtering, memory management
GUI Functionality Examples (13-18)
- Queue mode, inline mode, non-queue mode, multithreading, progress tracking, scroll management
Running Examples
# Run any example
python examples/01_basic_logging/example.py
# Or run the comprehensive demos
python examples/gui_example.py # Full GUI demonstration
python examples/export_example.py # Export functionality demo
python examples/cli_example.py # Command-line usage
Each example includes:
- โ Self-contained demonstration script
- โ Comprehensive README with documentation
- โ Interactive features and real-world scenarios
- โ Cross-references to related examples
๐ Recent Updates
Version 2.1.0 - Enhanced GUI & Examples
- โ 18 Complete Examples: Comprehensive coverage of all functionality
- โ GUI Enhancements: Queue mode, inline mode, non-queue mode
- โ Thread Safety: Full multithreading support for GUI
- โ Progress Tracking: Real-time progress updates with percentage
- โ Scroll Management: Intelligent auto-scroll with centered arrow button
- โ Memory Management: Automatic cleanup for long-running applications
- โ Export Improvements: Enhanced filtering and metadata support
Bug Fixes
- โ
Import Error Fix: Resolved
GUIModernLoggerimport issues - โ Arrow Centering: Fixed scroll-to-bottom button arrow alignment
- โ Thread Safety: Improved concurrent logging reliability
- โ Memory Leaks: Fixed GUI animation memory management
๐งช Testing
# Test basic functionality
python examples/01_basic_logging/example.py
# Test file logging
python examples/02_file_logging/example.py
# Test GUI functionality (requires PySide6)
python examples/10_gui_logging/example.py
# Test export functionality
python examples/export_example.py
# Test high-volume scenarios
python examples/18_gui_scroll_management/example.py
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Add tests for new functionality
- Ensure all examples work correctly
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
MIT License - see LICENSE file for details.
๐ Acknowledgments
- PySide6 for the modern GUI framework
- Colorama for cross-platform colored terminal output
- Qt Framework for robust GUI components
- Python Community for excellent logging standards
ModernLogger - Efficient, Beautiful, Modern Logging for Python ๐
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 modern_logger-1.0.0.tar.gz.
File metadata
- Download URL: modern_logger-1.0.0.tar.gz
- Upload date:
- Size: 53.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
462130933afaf75dd012902ddee34c5e36a99165ca083890a9409b2f4bf605b1
|
|
| MD5 |
9642539e4fc15ae651ee6509cf5de9a9
|
|
| BLAKE2b-256 |
d780795ed76b27166ca87697fbcc03a7cc61a5deef4cda24cd53c16d929829f9
|
File details
Details for the file modern_logger-1.0.0-py3-none-any.whl.
File metadata
- Download URL: modern_logger-1.0.0-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca42987d345c0299ef47c4a0637bd69be3fb1cb71b44c9450a80c6d46634d15e
|
|
| MD5 |
4390728b362aef34e949aedd97870a69
|
|
| BLAKE2b-256 |
281005e786bb77f24141fd5f985f53257f0fa83490710864effcee3f90c9b218
|