logscanner


Namelogscanner JSON
Version 0.9.3 PyPI version JSON
download
home_pageNone
SummaryA logger for python logging outputting to easily viewable (and filterable) html files. Good for people not grep savey, and color higlighting and quickly changing filters might even bye useful for commandline wizards.
upload_time2024-09-30 10:52:06
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT
keywords logging viewer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Logscanner

A simple proof of concept rendering python logging as html pages with a gui for quick filtering and analysis.
A single html file contains everything (html, css, javascript, logdata) so it is easy to pass along. If the log data should  be handled automatically, it is easy to either install an additional handler/formatter or to extract the json from the html file.

![LogScanner screenshot](doc/images/screenshot.png)

## Install

```pip install logscanner```

## Filtering

Currently the viewer allows to filter messages out based on the logger and the level of the message.

There are 4 filter settings, in descending priority order:

 1. show
 2. hide
 3. show-weak
 4. hide-weak

In general the hierarchy is based on a _don't hide the smoking gun philosophy_, i.e. in case of doubt messages are rather shown than hidden.

If a logger is set to _hide-weak_, the message will be hidden, unless a parent logger is set to _show_. Child logger messages will be displayed based on their visibility.

If a logger is set to _show-weak_, the message will be shown, unless a parent logger is set to _hide_. Child logger messages will be displayed based on their visibility.

If a logger is set to _hide_, the message will be hidden, unless a parent logger is set to _show_. Child logger messages will be hidden, unless they or a parent logger is set to _show_. Parent logger includes loggers above the logger which is set to _hide_.

If a logger is set to _show_, its messages and all the messages of child loggers will be shown.

The usual usage would be to set all loggers to _show-weak_ and remove all messages below a certain sublogger level by setting the topmost logger level below which messages should be hidden to _hide_.

## A word on the name
Original the project was supposed to be called `logviewer` but that name was taken on pypi, so here we are until we come up with a better name than `logscanner`.

# Example usage

The simplest way to use this with pytest is to use the pytest-logscanner plugin (`pip install logscanner[pytest]`).

```python
from logscanner import LogviewHandler
import logging

handler = LogviewHandler("your_logfile") # will generate the logfile your_logfile.html in the current directory, once the logger is shutdown.
logging.root.addHandler(handler)
logging.root.setLevel(logging.NOTSET)  # allow everything from the root logger

# Optional second handler to output to stderr
streamhandler = logging.StreamHandler()
streamhandler.setLevel(logging.INFO) # Filter on the handler, not on the logger
logging.root.addHandler(streamhandler)
```

In case you want to use this without the pytest plugin you could create a fixture like this in your conftest.py:

```python
import logging
from collections.abc import Generator

import pytest
from logscanner import LogviewHandler


@pytest.fixture(autouse=True)  # , scope="function")
def _setup_logging(request: pytest.FixtureRequest) -> Generator[None, None, None]:
    logfile = (
        request.path.parent / f"{request.path.name}_{request.function.__name__}.log"
    )

    # will generate the logfile your_logfile.html in the current directory,
    # once the logger is shutdown.
    handler = LogviewHandler(
        str(logfile),
    )
    logging.root.addHandler(handler)
    # allow everything from the root logger
    logging.root.setLevel(logging.NOTSET)

    yield

    logging.root.removeHandler(handler)
    handler.close()
```

# Building

```
pdm build
```


## Development

```
: build the html template
cd html
npm install
npm run build
cd ..
```

```
: might be useful for working on the template
npx webpack --watch
```

## project structure
in ./html is the source to create a html page with gui elements (css, javascript, fonts, etc.). The page is baked into a single file template using webpack. This file is bundled with a trivial logging formatter (json) and a logging handler which combines the json log and the html template into a single file log.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "logscanner",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "logging, viewer",
    "author": null,
    "author_email": "Malte Vesper <malte.vesper@gmx.net>",
    "download_url": "https://files.pythonhosted.org/packages/5e/d5/f6fd0b4ab26e9d67fcf3912f34ccf2605fca8fbaea5429a20f442adf093c/logscanner-0.9.3.tar.gz",
    "platform": null,
    "description": "# Logscanner\n\nA simple proof of concept rendering python logging as html pages with a gui for quick filtering and analysis.\nA single html file contains everything (html, css, javascript, logdata) so it is easy to pass along. If the log data should  be handled automatically, it is easy to either install an additional handler/formatter or to extract the json from the html file.\n\n![LogScanner screenshot](doc/images/screenshot.png)\n\n## Install\n\n```pip install logscanner```\n\n## Filtering\n\nCurrently the viewer allows to filter messages out based on the logger and the level of the message.\n\nThere are 4 filter settings, in descending priority order:\n\n 1. show\n 2. hide\n 3. show-weak\n 4. hide-weak\n\nIn general the hierarchy is based on a _don't hide the smoking gun philosophy_, i.e. in case of doubt messages are rather shown than hidden.\n\nIf a logger is set to _hide-weak_, the message will be hidden, unless a parent logger is set to _show_. Child logger messages will be displayed based on their visibility.\n\nIf a logger is set to _show-weak_, the message will be shown, unless a parent logger is set to _hide_. Child logger messages will be displayed based on their visibility.\n\nIf a logger is set to _hide_, the message will be hidden, unless a parent logger is set to _show_. Child logger messages will be hidden, unless they or a parent logger is set to _show_. Parent logger includes loggers above the logger which is set to _hide_.\n\nIf a logger is set to _show_, its messages and all the messages of child loggers will be shown.\n\nThe usual usage would be to set all loggers to _show-weak_ and remove all messages below a certain sublogger level by setting the topmost logger level below which messages should be hidden to _hide_.\n\n## A word on the name\nOriginal the project was supposed to be called `logviewer` but that name was taken on pypi, so here we are until we come up with a better name than `logscanner`.\n\n# Example usage\n\nThe simplest way to use this with pytest is to use the pytest-logscanner plugin (`pip install logscanner[pytest]`).\n\n```python\nfrom logscanner import LogviewHandler\nimport logging\n\nhandler = LogviewHandler(\"your_logfile\") # will generate the logfile your_logfile.html in the current directory, once the logger is shutdown.\nlogging.root.addHandler(handler)\nlogging.root.setLevel(logging.NOTSET)  # allow everything from the root logger\n\n# Optional second handler to output to stderr\nstreamhandler = logging.StreamHandler()\nstreamhandler.setLevel(logging.INFO) # Filter on the handler, not on the logger\nlogging.root.addHandler(streamhandler)\n```\n\nIn case you want to use this without the pytest plugin you could create a fixture like this in your conftest.py:\n\n```python\nimport logging\nfrom collections.abc import Generator\n\nimport pytest\nfrom logscanner import LogviewHandler\n\n\n@pytest.fixture(autouse=True)  # , scope=\"function\")\ndef _setup_logging(request: pytest.FixtureRequest) -> Generator[None, None, None]:\n    logfile = (\n        request.path.parent / f\"{request.path.name}_{request.function.__name__}.log\"\n    )\n\n    # will generate the logfile your_logfile.html in the current directory,\n    # once the logger is shutdown.\n    handler = LogviewHandler(\n        str(logfile),\n    )\n    logging.root.addHandler(handler)\n    # allow everything from the root logger\n    logging.root.setLevel(logging.NOTSET)\n\n    yield\n\n    logging.root.removeHandler(handler)\n    handler.close()\n```\n\n# Building\n\n```\npdm build\n```\n\n\n## Development\n\n```\n: build the html template\ncd html\nnpm install\nnpm run build\ncd ..\n```\n\n```\n: might be useful for working on the template\nnpx webpack --watch\n```\n\n## project structure\nin ./html is the source to create a html page with gui elements (css, javascript, fonts, etc.). The page is baked into a single file template using webpack. This file is bundled with a trivial logging formatter (json) and a logging handler which combines the json log and the html template into a single file log.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A logger for python logging outputting to easily viewable (and filterable) html files. Good for people not grep savey, and color higlighting and quickly changing filters might even bye useful for commandline wizards.",
    "version": "0.9.3",
    "project_urls": {
        "Changelog": "https://github.com/maltevesper/logscanner/blob/main/CHANGELOG.md",
        "Documentation": "https://maltevesper.github.io/logscanner/",
        "Repository": "https://github.com/maltevesper/logscanner"
    },
    "split_keywords": [
        "logging",
        " viewer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0cafc33ccac2f176fe134065b3d330ce7c013e5047add7a5bf303fcd1fd9130d",
                "md5": "0d3df055bace33f8662343bff7764403",
                "sha256": "392a8dc2b879e13cdd6eca5a19a473c188467dec5f25dcc15bdc971aa6765628"
            },
            "downloads": -1,
            "filename": "logscanner-0.9.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0d3df055bace33f8662343bff7764403",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 38753,
            "upload_time": "2024-09-30T10:52:04",
            "upload_time_iso_8601": "2024-09-30T10:52:04.787905Z",
            "url": "https://files.pythonhosted.org/packages/0c/af/c33ccac2f176fe134065b3d330ce7c013e5047add7a5bf303fcd1fd9130d/logscanner-0.9.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ed5f6fd0b4ab26e9d67fcf3912f34ccf2605fca8fbaea5429a20f442adf093c",
                "md5": "e9568f8ba4fbd7a68a366f689bc03995",
                "sha256": "8cd30829bbcac486fb7a1ceb297471c6e69db45653ccfff7d3909cd6fc054b0a"
            },
            "downloads": -1,
            "filename": "logscanner-0.9.3.tar.gz",
            "has_sig": false,
            "md5_digest": "e9568f8ba4fbd7a68a366f689bc03995",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 60441,
            "upload_time": "2024-09-30T10:52:06",
            "upload_time_iso_8601": "2024-09-30T10:52:06.857534Z",
            "url": "https://files.pythonhosted.org/packages/5e/d5/f6fd0b4ab26e9d67fcf3912f34ccf2605fca8fbaea5429a20f442adf093c/logscanner-0.9.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-30 10:52:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "maltevesper",
    "github_project": "logscanner",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "logscanner"
}
        
Elapsed time: 0.32618s