Skip to main content

Library for generating HTML logs with support for colors, rotation and filters via JavaScript.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

HTML Logger

A Python library for generating HTML logs with support for colors, file rotation, tagging, and JavaScript filters.

Features

  • ✅ Colored logs in HTML format
  • ✅ Automatic file rotation
  • ✅ Clean interface with integrated JavaScript filters
  • ✅ Thread-safe and high performance
  • ✅ Exception support with full traceback
  • ✅ Flexible configuration for file size and quantity
  • ✅ Tagging system for message categorization
  • ✅ Advanced filtering by tags and text content

Installation

pip install py-html-logger

Basic Usage

from htmllogger import log, error, report_exception

# Simple messages
log("Normal informative message")
log("Blue message", color="blue")

# Error messages
error("This is an error message")

# Log exceptions
try:
    # Your code here
    raise ValueError("Example error")
except Exception as e:
    report_exception(e)

Enhanced Tagging System

The logger supports tagging messages for better organization and filtering:

from htmllogger import log, info, debug, warning

# Simple tagged messages
log("User login", tag="auth")
info("Data processed", tag="processing")
debug("Variable value", tag="debug")
warning("Resource low", tag="system")

# Multiple tags
log("Security event", tag=["security", "monitoring"])

Configuration

from htmllogger import config

# Customize logger settings
config(
    max_files=15,           # Maximum number of log files
    max_size=5000000,       # Maximum size per file (5MB)
    main_filename="log.html", # Main file name
    log_dir="logs"          # Directory for logs
)

File Structure

Logs are stored in the specified directory (default: logs/) with the following structure:

logs/
└── log.html (current file)
└── 2023-10-05_12-30-45_log.html (rotated file)
└── 2023-10-05_10-15-32_log.html (rotated file)

Integrated JavaScript Filters

Generated HTML files include advanced filtering capabilities to facilitate analysis:

  • Text filtering with AND/OR logic
  • Tag-based filtering
  • Time period filtering
  • Real-time highlighting of matched terms
  • Preserved original log view

Complete Example

from htmllogger import log, info, debug, warning, error, report_exception, config

# Configure logger
config(
    max_files=10,
    max_size=2000000,  # 2MB
    log_dir="my_logs"
)

# Log with different tags and levels
log("Application started", tag="system", color="green")
info("Loading configuration", tag="config")
debug("Initializing modules", tag="debug")

for i in range(100):
    if i % 10 == 0:
        log(f"Checkpoint {i}", tag="checkpoint")
    info(f"Processing item {i}", tag="processing")

try:
    # Code that might raise an error
    result = 10 / 0
except Exception as e:
    error("Division by zero detected")
    report_exception(e)

log("Application finished", tag="system", color="green")

API Reference

log(message, color="white", tag=None)

Logs a message with optional color and tag(s).

info(message, color="white", tag=None)

Logs an informational message.

debug(message, color="white", tag=None)

Logs a debug message.

warning(message, color="gold", tag=None)

Logs a warning message.

error(message)

Logs an error message (in red).

report_exception(exc, timeout=None)

Logs an exception with its full traceback.

config(**kwargs)

Configures logger options:

  • max_files: Maximum number of files to maintain
  • max_size: Maximum size in bytes per file
  • main_filename: Main log file name
  • log_dir: Directory where logs will be stored

flush()

Processes all pending messages before termination.

Development

To contribute to the project:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Support

If you encounter issues or have questions:

  1. Check the documentation
  2. Open an issue
  3. Contact: rphspires@gmail.com

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Developed by Raphael Pires
  • Inspired by the need for better log visualization and analysis tools

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

py_html_logger-0.1.5.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

py_html_logger-0.1.5-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file py_html_logger-0.1.5.tar.gz.

File metadata

  • Download URL: py_html_logger-0.1.5.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for py_html_logger-0.1.5.tar.gz
Algorithm Hash digest
SHA256 50d0343afa859111644a3e3c1681c3308253f8d6fd0e1afa9fc86ffde36d54c8
MD5 4532c9ae326148ae5d227924f6a4f57c
BLAKE2b-256 e8d6a58096d95e185bffa464583b3e830b068fc0bac61377e4e5552cc7940373

See more details on using hashes here.

File details

Details for the file py_html_logger-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: py_html_logger-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for py_html_logger-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bb2ebf9eacaa65a0c347619ecb819f75dd0ead6a4f09af7c295c3dc8853a2705
MD5 8b1133dc15ec02918d9c9b8edb135898
BLAKE2b-256 0fc462574d7dabd4cf4aeb3e611b142882cce17169d86b6cf7e665bc7011eda7

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