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.
This library was written for Hackt CLI and open sourced for anyone interested.
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 AsyncHttpHandler
logger = logging.getLogger()
logger.addHandler(AsyncHttpHandler(
host='your-domain.com',
port=443, # Optional, defaults to 80 (HTTP) or 443 (HTTPS/TLS enabled)
path='/my-logs', # Appended to the host (i.e. your-domain.com/app-logs)
ssl_enable=True, # Default: True, may set to False on a dev environment
ssl_verify=True, # Default: True, may set to False on a dev environment
database_path='local-cache-logs.db', # SQLite DB filepath to cache logs
))
logger.info('Some useful information...')
logger.error('Ooops!')
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"
},
"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": "Ooops!",
"level": {
"number": 40,
"name": "ERROR"
},
"sourcecode": {
"pathname": "/path/to/your/python/script.py",
"function": "function_name",
"line": 456
},
"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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for http_logging-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21c03ef63b50b6b2538f6918905fa0b7bc9bb12babf72bc272e522416b04ad9e |
|
MD5 | 8b41ff3d766a8a98391f0a7df1e83e6e |
|
BLAKE2b-256 | a06592efc7d4915379070322a38cd6c99183acf14d3d46790487c5218fb3aa80 |