Skip to main content

Alternative to Python's module `cgitb` with template inspired by Nette and Django

Project description

https://api.travis-ci.org/miso-belica/diagnostics.png?branch=master

Module for logging of detailed traceback as HTML page. Unexpected exceptions are catched and logged for further audit. Exceptions in diagnostic’s exception handler are properly handled and logged (but formatted only as standard Python traceback). Usage is simple as code below.

from diagnostics import exception_hook

if __name__ == '__main__':
    # you have to create "log/" directory next to file that is your main module
    exception_hook.enable()
from diagnostics import exception_hook
from diagnostics.storages import FileStorage

if __name__ == '__main__':
    # or simply set your own storage
    directory_path = "/path/to/your/log/directory/with/html/tracebacks"
    exception_hook.enable(storage=FileStorage(directory_path))
from diagnostics import exception_hook

if __name__ == '__main__':
    with exception_hook:
        try_do_risky_job(...)

There is even support for logging in diagnostics. Class diagnostics.logging.FileHandler creates files with detailed traceback and log messages are appended to the file info.log in directory with logged tracebacks.

import logging

from diagnostics import exception_hook
from diagnostics.logging import FileHandler

if __name__ == '__main__':
    file_path = "/path/to/log/directory/with/html/tracebacks/info.log"
    log_handler = FileHandler(file_path)
    exception_hook.enable_for_logger(logging.getLogger(), handler=log_handler)

    try:
        try_do_risky_job(...)
    except:
        logging.exception("Risky job failed")
import logging

from diagnostics import exception_hook
from diagnostics.logging import FileHandler

if __name__ == '__main__':
    file_path = "/path/to/log/directory/with/html/tracebacks/info.log"
    log_handler = FileHandler(file_path)
    exception_hook.enable_for_logger("example_logger", handler=log_handler)

    try:
        try_do_risky_job(...)
    except:
        logger = logging.getLogger("example_logger")
        logger.error("Error occured", exc_info=True)

Installation

From PyPI

pip install diagnostics

or from git repo

pip install git+git://github.com/miso-belica/diagnostics.git

Tests

Run tests via

$ nosetests-2.6 && nosetests-3.2 && nosetests-2.7 && nosetests-3.3

Changelog for diagnostics module

0.2.4 (2014-04-14)

  • BUG FIX: Correctly logged traceback if no exception occured.

0.2.3 (2013-11-15)

  • BUG FIX: Context code is rendered with correct line number even when exception is raised from with-statement block.

  • BUG FIX: Added time and logging level name into log messages.

0.2.2 (2013-10-05)

  • BUG FIX: Fixed usage in terminal.

  • BUG FIX: Fixed reading of JS/CSS file in Python 3. HTML traceback is properly rendered.

0.2.1 (2013-10-04)

  • FEATURE: Removed empty trailing lines from context code.

  • BUG FIX: Removed duplicated global variables from list of local variables.

  • BUG FIX: Don’t show types/modules/functions in list of local variables.

0.2.0 (2013-06-22)

  • BUG FIX: Removed class types, modules and other crap from list of global variables.

  • BUG FIX: Function/method variables are ordered according to function/method signature.

  • FEATURE: The same exceptions are stored only once (according to their hash).

  • BUG FIX: Recover when converting object to unicode raises exception (e.g. BeautifulSoup).

  • BUG FIX: Format code context even if code is in binary form (e.g. lxml).

  • BUG FIX: Use repr function when instance can’t be de/en-coded to the unicode/bytes.

  • BUG FIX: Tracebacks with the same type of exception and timestamp are stored to different files.

  • FEATURE: Added support for with statement.

  • FEATURE: Added logging support.

0.1.0 (2013-02-13)

  • First public release.

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

diagnostics-0.2.4.zip (29.1 kB view details)

Uploaded Source

Built Distributions

diagnostics-0.2.4.win32.exe (223.9 kB view details)

Uploaded Source

diagnostics-0.2.4-py2.py3-none-any.whl (25.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file diagnostics-0.2.4.zip.

File metadata

  • Download URL: diagnostics-0.2.4.zip
  • Upload date:
  • Size: 29.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for diagnostics-0.2.4.zip
Algorithm Hash digest
SHA256 11fc6f9b9c9a30f926d19b8d57cf62aca750323097eda85c3d2a3da880d3f65e
MD5 328ebcb606868877883d4d01194b9ce9
BLAKE2b-256 324cfe783877a8d754c1485ba0b0a7d25d0434efd59f57d0dd64be8239f4f07d

See more details on using hashes here.

File details

Details for the file diagnostics-0.2.4.win32.exe.

File metadata

File hashes

Hashes for diagnostics-0.2.4.win32.exe
Algorithm Hash digest
SHA256 40e635fcce55175e7bcaa9b48f127d5fb37f1b8d16110503731605c568af8c45
MD5 5b978a46b56c84f96c92fc2dfa79c8c8
BLAKE2b-256 b9de995c1a1fbb82400768e6c1bfa97308ea6d74bc9cad60edff0b3d6168df27

See more details on using hashes here.

File details

Details for the file diagnostics-0.2.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for diagnostics-0.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9034490062c307b2bf85ca871fc7fe7b5e47883a43945491ff3712abd64ece98
MD5 788dcbdf8b18e52d5b3e1196cfe2ffb3
BLAKE2b-256 9abeab13f03cfae2c37620c14fe7d100527b369e2e4559e730d88233eeefb03c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page