
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
loghtml
Advanced tools
Library for generating HTML logs with support for colors, rotation and filters via JavaScript. Optimized for continuous applications.
A Python library for generating HTML logs with support for colors, file rotation, tagging, and JavaScript filters.
pip install loghtml
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)
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")
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)
from loghtml import log_html_config
# Customize logger settings
log_html_config(
log_files_limit_count=15, # Maximum number of log files
log_files_limit_size=5000000, # Maximum size per file (5MB)
main_filename="log.html", # Main file name
log_dir="logs", # Directory for logs
immediate_flush=True # Flush after every write (default: True)
)
The logger is optimized for continuous (long-running) applications with immediate flush mode enabled by default. This ensures that log messages are written to the file immediately, making them visible even if the application doesn't terminate.
For high-volume logging scenarios, you can disable immediate flush for better performance:
from loghtml import log_html_config
# Optimize for high-volume logging
log_html_config(
immediate_flush=False # Use buffering (flushes every 1s or 64KB)
)
Note: For typical continuous applications (servers, daemons, monitoring tools), keep immediate_flush=True (default) to ensure real-time log visibility.
The logger includes two file-based validation features that provide runtime control over logging behavior:
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_debugEnableDebugfrom 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
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_disableLogDisablefrom 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.
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)
Generated HTML files include advanced filtering capabilities to facilitate analysis:
from loghtml import log, info, debug, warning, error, report_exception, log_html_config, set_default_tag_color
# Configure logger
log_html_config(
log_files_limit_count=10,
log_files_limit_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")
Logs a message with optional color and tag(s).
Logs an informational message.
Logs a debug message.
Logs a warning message.
Logs an error message (in red).
Logs an exception with its full traceback.
Configures logger options:
log_files_limit_count: Maximum number of files to maintainlog_files_limit_size: Maximum size in bytes per filemain_filename: Main log file namelog_dir: Directory where logs will be storedSets default colors for specific tags:
color_dict: Dictionary mapping tag names to color valuesProcesses all pending messages before termination.
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:
hook-loghtml.py)importlib.resourceszip-safe = false configuration for maximum compatibilitySee PYINSTALLER_GUIDE.md for detailed instructions and troubleshooting.
To contribute to the project:
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)If you encounter issues or have questions:
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
Library for generating HTML logs with support for colors, rotation and filters via JavaScript. Optimized for continuous applications.
We found that loghtml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.