loghtml


Nameloghtml JSON
Version 0.1.17 PyPI version JSON
download
home_pageNone
SummaryLibrary for generating HTML logs with support for colors, rotation and filters via JavaScript.
upload_time2025-09-15 15:36:03
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords logging html logger logs colors trace loghtml web log html logger
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash
pip install loghtml
```

## Basic Usage

```python
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:

```python
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:

```python
from loghtml import set_default_tag_color

default_tag_colors = {
    "database": "LightGrey",
    "connection": "LightBlue",
    "heartbeat": "Yellow"
}
set_default_tag_color(default_tag_colors)
```

## Configuration

```python
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 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

```python
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 maintain
- `max_size`: Maximum size in bytes per file
- `main_filename`: Main log file name
- `log_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:

```bash
# 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 = false` configuration for maximum compatibility

See `PYINSTALLER_GUIDE.md` for detailed instructions and troubleshooting.

## 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](https://github.com/rphpires/py-html-logger)
2. Open an [issue](https://github.com/rphpires/py-html-logger/issues)
3. Contact: rphspires@gmail.com

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "loghtml",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "logging, html, logger, logs, colors, trace, loghtml, web log, html logger",
    "author": null,
    "author_email": "Raphael Pires Nome <rphspires@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/6b/87/3813c23e12d25f78c09bc377c7d0644b51a1845df7c42ba67f115b2afd5c/loghtml-0.1.17.tar.gz",
    "platform": null,
    "description": "# HTML Logger\r\n\r\nA Python library for generating HTML logs with support for colors, file rotation, tagging, and JavaScript filters.\r\n\r\n## Features\r\n\r\n- \u2705 Colored logs in HTML format\r\n- \u2705 Automatic file rotation\r\n- \u2705 Clean interface with integrated JavaScript filters\r\n- \u2705 Thread-safe and high performance\r\n- \u2705 Exception support with full traceback\r\n- \u2705 Flexible configuration for file size and quantity\r\n- \u2705 Tagging system for message categorization\r\n- \u2705 Advanced filtering by tags and text content\r\n- \u2705 Default color mapping for specific tags\r\n\r\n## Installation\r\n\r\n```bash\r\npip install loghtml\r\n```\r\n\r\n## Basic Usage\r\n\r\n```python\r\nfrom loghtml import log, error, report_exception\r\n\r\n# Simple messages\r\nlog(\"Normal informative message\")\r\nlog(\"Blue message\", color=\"blue\")\r\n\r\n# Error messages\r\nerror(\"This is an error message\")\r\n\r\n# Log exceptions\r\ntry:\r\n    # Your code here\r\n    raise ValueError(\"Example error\")\r\nexcept Exception as e:\r\n    report_exception(e)\r\n```\r\n\r\n## Enhanced Tagging System\r\n\r\nThe logger supports tagging messages for better organization and filtering:\r\n\r\n```python\r\nfrom loghtml import log, info, debug, warning\r\n\r\n# Tagged messages\r\nlog(\"User login\", tag=\"auth\")\r\ninfo(\"Data processed\", tag=\"processing\")\r\ndebug(\"Variable value\", tag=\"debug\")\r\nwarning(\"Resource low\", tag=\"system\")\r\n```\r\n\r\n## Setting Default Tag Colors\r\n\r\nYou can define default colors for specific tags:\r\n\r\n```python\r\nfrom loghtml import set_default_tag_color\r\n\r\ndefault_tag_colors = {\r\n    \"database\": \"LightGrey\",\r\n    \"connection\": \"LightBlue\",\r\n    \"heartbeat\": \"Yellow\"\r\n}\r\nset_default_tag_color(default_tag_colors)\r\n```\r\n\r\n## Configuration\r\n\r\n```python\r\nfrom loghtml import config\r\n\r\n# Customize logger settings\r\nconfig(\r\n    max_files=15,           # Maximum number of log files\r\n    max_size=5000000,       # Maximum size per file (5MB)\r\n    main_filename=\"log.html\", # Main file name\r\n    log_dir=\"logs\"          # Directory for logs\r\n)\r\n```\r\n\r\n## File Structure\r\n\r\nLogs are stored in the specified directory (default: `logs/`) with the following structure:\r\n\r\n```\r\nlogs/\r\n\u2514\u2500\u2500 log.html (current file)\r\n\u2514\u2500\u2500 2023-10-05_12-30-45_log.html (rotated file)\r\n\u2514\u2500\u2500 2023-10-05_10-15-32_log.html (rotated file)\r\n```\r\n\r\n## Integrated JavaScript Filters\r\n\r\nGenerated HTML files include advanced filtering capabilities to facilitate analysis:\r\n\r\n- Text filtering with AND/OR logic\r\n- Tag-based filtering\r\n- Time period filtering\r\n- Real-time highlighting of matched terms\r\n- Preserved original log view\r\n\r\n## Complete Example\r\n\r\n```python\r\nfrom loghtml import log, info, debug, warning, error, report_exception, config, set_default_tag_color\r\n\r\n# Configure logger\r\nconfig(\r\n    max_files=10,\r\n    max_size=2000000,  # 2MB\r\n    log_dir=\"my_logs\"\r\n)\r\n\r\n# Set default tag colors\r\ndefault_tag_colors = {\r\n    \"system\": \"green\",\r\n    \"processing\": \"cyan\",\r\n    \"checkpoint\": \"magenta\"\r\n}\r\nset_default_tag_color(default_tag_colors)\r\n\r\n# Log with different tags and levels\r\nlog(\"Application started\", tag=\"system\")\r\ninfo(\"Loading configuration\", tag=\"config\")\r\ndebug(\"Initializing modules\", tag=\"debug\")\r\n\r\nfor i in range(100):\r\n    if i % 10 == 0:\r\n        log(f\"Checkpoint {i}\", tag=\"checkpoint\")\r\n    info(f\"Processing item {i}\", tag=\"processing\")\r\n\r\ntry:\r\n    # Code that might raise an error\r\n    result = 10 / 0\r\nexcept Exception as e:\r\n    error(\"Division by zero detected\")\r\n    report_exception(e)\r\n\r\nlog(\"Application finished\", tag=\"system\")\r\n```\r\n\r\n## API Reference\r\n\r\n### log(message, color=None, tag=\"log\")\r\nLogs a message with optional color and tag(s).\r\n\r\n### info(message, color=None, tag=\"info\")\r\nLogs an informational message.\r\n\r\n### debug(message, color=None, tag=\"debug\")\r\nLogs a debug message.\r\n\r\n### warning(message, color=None, tag=\"warning\")\r\nLogs a warning message.\r\n\r\n### error(message, tag=\"error\")\r\nLogs an error message (in red).\r\n\r\n### report_exception(exc, timeout=None)\r\nLogs an exception with its full traceback.\r\n\r\n### config(**kwargs)\r\nConfigures logger options:\r\n- `max_files`: Maximum number of files to maintain\r\n- `max_size`: Maximum size in bytes per file\r\n- `main_filename`: Main log file name\r\n- `log_dir`: Directory where logs will be stored\r\n\r\n### set_default_tag_color(color_dict)\r\nSets default colors for specific tags:\r\n- `color_dict`: Dictionary mapping tag names to color values\r\n\r\n### flush()\r\nProcesses all pending messages before termination.\r\n\r\n## Using with PyInstaller\r\n\r\nThe package is now fully compatible with PyInstaller and includes automatic hook detection:\r\n\r\n```bash\r\n# Basic usage\r\npyinstaller --onefile your_script.py\r\n\r\n# If you need additional debugging\r\npyinstaller --collect-all loghtml --onefile your_script.py\r\n```\r\n\r\nThe package includes:\r\n- Automatic PyInstaller hook (`hook-loghtml.py`)\r\n- Proper resource management using `importlib.resources`\r\n- `zip-safe = false` configuration for maximum compatibility\r\n\r\nSee `PYINSTALLER_GUIDE.md` for detailed instructions and troubleshooting.\r\n\r\n## Development\r\n\r\nTo contribute to the project:\r\n\r\n1. Fork the repository\r\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`)\r\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)\r\n4. Push to the branch (`git push origin feature/AmazingFeature`)\r\n5. Open a Pull Request\r\n\r\n## Support\r\n\r\nIf you encounter issues or have questions:\r\n\r\n1. Check the [documentation](https://github.com/rphpires/py-html-logger)\r\n2. Open an [issue](https://github.com/rphpires/py-html-logger/issues)\r\n3. Contact: rphspires@gmail.com\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n## Acknowledgments\r\n\r\n- Developed by Raphael Pires\r\n- Inspired by the need for better log visualization and analysis tools\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Library for generating HTML logs with support for colors, rotation and filters via JavaScript.",
    "version": "0.1.17",
    "project_urls": {
        "Bug Tracker": "https://github.com/rphpires/py-html-logger/issues",
        "Homepage": "https://github.com/rphpires/py-html-logger"
    },
    "split_keywords": [
        "logging",
        " html",
        " logger",
        " logs",
        " colors",
        " trace",
        " loghtml",
        " web log",
        " html logger"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "af2a114e55ca73556581fdfdf277ad146c6142dc23c3a9a4e07cefd4648e6216",
                "md5": "7a6c004a8deeab0d5a58cae662375829",
                "sha256": "cf9e31b7ef7f95fdecb0f9b349f9d330d9ceb7f41bd3ad97a4bad0fecb3a81c8"
            },
            "downloads": -1,
            "filename": "loghtml-0.1.17-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7a6c004a8deeab0d5a58cae662375829",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12855,
            "upload_time": "2025-09-15T15:36:01",
            "upload_time_iso_8601": "2025-09-15T15:36:01.855748Z",
            "url": "https://files.pythonhosted.org/packages/af/2a/114e55ca73556581fdfdf277ad146c6142dc23c3a9a4e07cefd4648e6216/loghtml-0.1.17-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6b873813c23e12d25f78c09bc377c7d0644b51a1845df7c42ba67f115b2afd5c",
                "md5": "da174e01aaf361635b0d5af41b12d631",
                "sha256": "f3307cb04aca4fc88ff77d58a59037ca7a71c5f46f41024e0e5a37599122bdc3"
            },
            "downloads": -1,
            "filename": "loghtml-0.1.17.tar.gz",
            "has_sig": false,
            "md5_digest": "da174e01aaf361635b0d5af41b12d631",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16316,
            "upload_time": "2025-09-15T15:36:03",
            "upload_time_iso_8601": "2025-09-15T15:36:03.078156Z",
            "url": "https://files.pythonhosted.org/packages/6b/87/3813c23e12d25f78c09bc377c7d0644b51a1845df7c42ba67f115b2afd5c/loghtml-0.1.17.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-15 15:36:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rphpires",
    "github_project": "py-html-logger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "loghtml"
}
        
Elapsed time: 1.38549s