py-html-logger


Namepy-html-logger JSON
Version 0.1.16 PyPI version JSON
download
home_pageNone
SummaryLibrary for generating HTML logs with support for colors, rotation and filters via JavaScript.
upload_time2025-08-30 22:20:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords logging html logger logs colors trace loghtml web log loghtml py-html-logger html logger logging
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 py-html-logger
```

## 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.

## 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": "py-html-logger",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "logging, html, logger, logs, colors, trace, loghtml, web log, loghtml, py-html-logger, html logger, logging",
    "author": null,
    "author_email": "Raphael Pires Nome <rphspires@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/14/0e/f032205122b693cefd2fcb68559825a013d85c1fba351b3a69d77e93ac9f/py_html_logger-0.1.16.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 py-html-logger\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## 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.16",
    "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",
        " loghtml",
        " py-html-logger",
        " html logger",
        " logging"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "275ad934f7c500c36b652089beaac4d19f649058b3d3d7ff54f6393aaf117afc",
                "md5": "07d5a7a0bf36cd582c696a0fb75270a5",
                "sha256": "ac5ac4290eb0db0b3eac0e363048dce1384c1b9835334db15275a8b44238054b"
            },
            "downloads": -1,
            "filename": "py_html_logger-0.1.16-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "07d5a7a0bf36cd582c696a0fb75270a5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12364,
            "upload_time": "2025-08-30T22:20:40",
            "upload_time_iso_8601": "2025-08-30T22:20:40.011559Z",
            "url": "https://files.pythonhosted.org/packages/27/5a/d934f7c500c36b652089beaac4d19f649058b3d3d7ff54f6393aaf117afc/py_html_logger-0.1.16-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "140ef032205122b693cefd2fcb68559825a013d85c1fba351b3a69d77e93ac9f",
                "md5": "d9e168433dd446f0a5911ec478a0db40",
                "sha256": "192ea091e8d1dc22a0789fc8f3c12d6869fa6fd352f89dfe1b4111901c8ccc09"
            },
            "downloads": -1,
            "filename": "py_html_logger-0.1.16.tar.gz",
            "has_sig": false,
            "md5_digest": "d9e168433dd446f0a5911ec478a0db40",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 15342,
            "upload_time": "2025-08-30T22:20:41",
            "upload_time_iso_8601": "2025-08-30T22:20:41.368915Z",
            "url": "https://files.pythonhosted.org/packages/14/0e/f032205122b693cefd2fcb68559825a013d85c1fba351b3a69d77e93ac9f/py_html_logger-0.1.16.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-30 22:20:41",
    "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": "py-html-logger"
}
        
Elapsed time: 1.98697s