Skip to main content

Non-blocking HTTP handler for Python `logging` with local SQLite buffer/cache.

Project description

Asynchronous HTTP Logging

Non-blocking HTTP handler for Python logging with local SQLite buffer/cache.

Test Coverage Maintained Maintainability Technical Debt Issues CodeFactor

Requirements Status PyPI License

Code Style Code Formatter Test Framework

Documentation

Please refer to the project Wiki.

Installation

Virtual environment is highly recommended.

pip install http_logging

Basic usage

import logging

from http_logging import HttpHost
from http_logging.handler import AsyncHttpHandler

log_handler = AsyncHttpHandler(http_host=HttpHost(name='your-domain.com'))

logger = logging.getLogger()
logger.addHandler(log_handler)

# Works with simple log messages like:
logger.info('Some useful information...')

# Can also handle extra fields:
logger.warning('You\'ve been warned!', extra={'foo': 'bar'})

# And, of course, captures exception with full stack-trace
try:
    1/0
except Exception as exc:
    logger.error('Ooops!', exc_info=exc)

These log messages are cached in a local SQLite database and periodically delivered (asynchronously, in a separate thread) to your host in a POST request with a body similar to this one:

[
    {
        "type": "async-http-logging",
        "created": 1610393068.365492,
        "relative_created": 1505.5122375488281,
        "message": "Some useful information...",
        "level": {
            "number": 20,
            "name": "INFO"
        },
        "stack_trace": null,
        "sourcecode": {
            "pathname": "/path/to/your/python/script.py",
            "function": "function_name",
            "line": 123
        },
        "process": {
            "id": 1234,
            "name": "MainProcess"
        },
        "thread": {
            "id": 1234567890,
            "name": "MainThread"
        }
    },
    {
        "type": "async-http-logging",
        "created": 1610393068.3663092,
        "relative_created": 1506.3292980194092,
        "message": "You've been warned!",
        "level": {
            "number": 30,
            "name": "WARNING"
        },
        "stack_trace": null,
        "sourcecode": {
            "pathname": "/path/to/your/python/script.py",
            "function": "function_name",
            "line": 456
        },
        "process": {
            "id": 1234,
            "name": "MainProcess"
        },
        "thread": {
            "id": 1234567890,
            "name": "MainThread"
        }
    },
    {
        "type": "async-http-logging",
        "created": 1610393068.3663092,
        "relative_created": 1506.3292980194092,
        "message": "Ooops!",
        "level": {
            "number": 40,
            "name": "ERROR"
        },
        "stack_trace": "Traceback (most recent call last):\n  File \"/path/to/your/python/script.py\", line 17, in function_name\n    1/0\nZeroDivisionError: division by zero\n",
        "sourcecode": {
            "pathname": "/path/to/your/python/script.py",
            "function": "function_name",
            "line": 17
        },
        "process": {
            "id": 1234,
            "name": "MainProcess"
        },
        "thread": {
            "id": 1234567890,
            "name": "MainThread"
        }
    }
]

In your backend, you can funnel these logs to wherever suits you best: database, ElasticSearch index, third-party monitoring service, etc.

Learn more about these and other features in the project Wiki.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

http_logging-2.0.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file http_logging-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: http_logging-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.2 CPython/3.8.2

File hashes

Hashes for http_logging-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b8c58775af1083ce6ddaec76da0fcdaef5617d42af4730dfea0b9b5c4192993
MD5 71dc38a29d7e84b3989b2b32bb3ff7bc
BLAKE2b-256 8372d2ca51ed112c92b71f9bda7ab9a6df8a0474f9fc9ce55f3db2db5f8ced8e

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