Library for generating HTML logs with support for colors, rotation and filters via JavaScript.
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
- ✅ Default color mapping for specific tags
Installation
pip install loghtml
Basic Usage
from loghtml 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 loghtml import log, info, debug, warning
# Tagged messages
log("User login", tag="auth")
info("Data processed", tag="processing")
debug("Variable value", tag="debug")
warning("Resource low", tag="system")
Setting Default Tag Colors
You can define default colors for specific tags:
from loghtml import set_default_tag_color
default_tag_colors = {
"database": "LightGrey",
"connection": "LightBlue",
"heartbeat": "Yellow"
}
set_default_tag_color(default_tag_colors)
Configuration
from loghtml 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-based Control Features
The logger includes two file-based validation features that provide runtime control over logging behavior:
Debug Mode Control
Debug messages can be enabled by creating a control file in your application directory. The logger will automatically detect the presence of any of these files:
DebugEnabledebug_enableenable_debugEnableDebug
from loghtml import debug, log
# Create a control file to enable debug messages
# On Windows:
# type nul > DebugEnable
# On Linux/Mac:
# touch debug_enable
debug("This debug message will only appear if debug control file exists")
log("This regular message always appears")
Example usage:
# Enable debug mode
touch debug_enable
# Run your application - debug messages will now be visible
python your_app.py
# Disable debug mode
rm debug_enable
# Run again - debug messages will be hidden
python your_app.py
Log Disable Control
All log writing to files can be disabled by creating a control file in your application directory. The logger will automatically detect the presence of any of these files:
DisableLogdisable_loglog_disableLogDisable
from loghtml import log, info, error
# Create a control file to disable all log file writing
# On Windows:
# type nul > DisableLog
# On Linux/Mac:
# touch disable_log
log("This message will still appear on screen but not in log files")
info("Screen output continues normally")
error("Errors are still displayed on screen")
Example usage:
# Disable log file writing (console output still works)
touch disable_log
# Run your application - no log files will be created/updated
python your_app.py
# Re-enable log file writing
rm disable_log
# Run again - log files will be created/updated normally
python your_app.py
Note: These control files only need to exist in the same directory where your application runs. The content of the files is irrelevant - only their presence matters. Screen output (console logging) continues to work regardless of these settings.
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 loghtml import log, info, debug, warning, error, report_exception, config, set_default_tag_color
# Configure logger
config(
max_files=10,
max_size=2000000, # 2MB
log_dir="my_logs"
)
# Set default tag colors
default_tag_colors = {
"system": "green",
"processing": "cyan",
"checkpoint": "magenta"
}
set_default_tag_color(default_tag_colors)
# Log with different tags and levels
log("Application started", tag="system")
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")
API Reference
log(message, color=None, tag="log")
Logs a message with optional color and tag(s).
info(message, color=None, tag="info")
Logs an informational message.
debug(message, color=None, tag="debug")
Logs a debug message.
warning(message, color=None, tag="warning")
Logs a warning message.
error(message, tag="error")
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 maintainmax_size: Maximum size in bytes per filemain_filename: Main log file namelog_dir: Directory where logs will be stored
set_default_tag_color(color_dict)
Sets default colors for specific tags:
color_dict: Dictionary mapping tag names to color values
flush()
Processes all pending messages before termination.
Using with PyInstaller
The package is now fully compatible with PyInstaller and includes automatic hook detection:
# Basic usage
pyinstaller --onefile your_script.py
# If you need additional debugging
pyinstaller --collect-all loghtml --onefile your_script.py
The package includes:
- Automatic PyInstaller hook (
hook-loghtml.py) - Proper resource management using
importlib.resources zip-safe = falseconfiguration for maximum compatibility
See PYINSTALLER_GUIDE.md for detailed instructions and troubleshooting.
Development
To contribute to the project:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Support
If you encounter issues or have questions:
- Check the documentation
- Open an issue
- 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
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 loghtml-0.1.20.tar.gz.
File metadata
- Download URL: loghtml-0.1.20.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60d140b7d5e5fabf261cdbbf590b787a25c04c256499e8d4f885c5b96bdf3084
|
|
| MD5 |
44423d2a7cbc477eacb19964d060e33e
|
|
| BLAKE2b-256 |
ff138c8011bc36155f35c10eb36024b1a79897d93775a2cb04d5a0354e64f225
|
File details
Details for the file loghtml-0.1.20-py3-none-any.whl.
File metadata
- Download URL: loghtml-0.1.20-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8aaf5c4c4c911b6b6552c9802977c841dee3a8f53ab1f4725f74b9a9ca1e1478
|
|
| MD5 |
8bf75f25a67aad68488fd32710606a93
|
|
| BLAKE2b-256 |
6b6a859a6ae079c7f58b42fe7ded37d13d8c76db2724dcd2c72d3c2f01109b9c
|