Skip to main content

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] or pip 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 GUIModernLogger import 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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Add tests for new functionality
  4. Ensure all examples work correctly
  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

๐Ÿ“„ 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


Download files

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

Source Distribution

modern_logger-1.0.0.tar.gz (53.1 kB view details)

Uploaded Source

Built Distribution

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

modern_logger-1.0.0-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

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

Hashes for modern_logger-1.0.0.tar.gz
Algorithm Hash digest
SHA256 462130933afaf75dd012902ddee34c5e36a99165ca083890a9409b2f4bf605b1
MD5 9642539e4fc15ae651ee6509cf5de9a9
BLAKE2b-256 d780795ed76b27166ca87697fbcc03a7cc61a5deef4cda24cd53c16d929829f9

See more details on using hashes here.

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

Hashes for modern_logger-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca42987d345c0299ef47c4a0637bd69be3fb1cb71b44c9450a80c6d46634d15e
MD5 4390728b362aef34e949aedd97870a69
BLAKE2b-256 281005e786bb77f24141fd5f985f53257f0fa83490710864effcee3f90c9b218

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