# Asynchronous HTTP Logging
Non-blocking HTTP handler for Python `logging` with local SQLite buffer/cache.
> This library was written for [Hackt CLI](https://hackt.app/?utm_source=github&utm_medium=gitlink&utm_campaign=oss-py-async-http-logging) and open sourced for anyone interested.


[](https://codeclimate.com/github/hacktlib/py-async-http-logging)
[](https://codeclimate.com/github/hacktlib/py-async-http-logging)
[](https://codeclimate.com/github/hacktlib/py-async-http-logging/issues?category=complexity&engine_name%5B%5D=structure&engine_name%5B%5D=duplication)
[](https://www.codefactor.io/repository/github/hacktlib/py-async-http-logging)
[](https://requires.io/github/hacktlib/py-async-http-logging/requirements/?branch=main)
[](https://pypi.org/project/http_logging/)
[](https://opensource.org/licenses/Apache-2.0)
[](https://github.com/hhatto/autopep8/)
[](https://github.com/hhatto/autopep8/)
[](https://github.com/pytest-dev/pytest/)
## Documentation
Please refer to the [project Wiki](https://github.com/hacktlib/py-async-http-logging/wiki).
## Installation
> [Virtual environment](https://docs.python.org/3/tutorial/venv.html) is highly recommended.
```shell
pip install http_logging
```
## Basic usage
```python
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:
```json
[
{
"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](https://github.com/hacktlib/py-async-http-logging/wiki).
Raw data
{
"_id": null,
"home_page": "https://github.com/hacktlib/py-async-http-logging/wiki",
"name": "http-logging",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6, <4",
"maintainer_email": "",
"keywords": "",
"author": "Hackt.app",
"author_email": "opensource@hackt.app",
"download_url": "",
"platform": "",
"description": "# Asynchronous HTTP Logging\n\nNon-blocking HTTP handler for Python `logging` with local SQLite buffer/cache.\n\n> This library was written for [Hackt CLI](https://hackt.app/?utm_source=github&utm_medium=gitlink&utm_campaign=oss-py-async-http-logging) and open sourced for anyone interested.\n\n\n\n[](https://codeclimate.com/github/hacktlib/py-async-http-logging)\n[](https://codeclimate.com/github/hacktlib/py-async-http-logging)\n[](https://codeclimate.com/github/hacktlib/py-async-http-logging/issues?category=complexity&engine_name%5B%5D=structure&engine_name%5B%5D=duplication)\n[](https://www.codefactor.io/repository/github/hacktlib/py-async-http-logging)\n\n[](https://requires.io/github/hacktlib/py-async-http-logging/requirements/?branch=main)\n[](https://pypi.org/project/http_logging/)\n[](https://opensource.org/licenses/Apache-2.0)\n\n[](https://github.com/hhatto/autopep8/)\n[](https://github.com/hhatto/autopep8/)\n[](https://github.com/pytest-dev/pytest/)\n\n\n## Documentation\n\nPlease refer to the [project Wiki](https://github.com/hacktlib/py-async-http-logging/wiki).\n\n\n## Installation\n\n> [Virtual environment](https://docs.python.org/3/tutorial/venv.html) is highly recommended.\n\n```shell\npip install http_logging\n```\n\n\n## Basic usage\n\n```python\nimport logging\n\nfrom http_logging import HttpHost\nfrom http_logging.handler import AsyncHttpHandler\n\nlog_handler = AsyncHttpHandler(http_host=HttpHost(name='your-domain.com'))\n\nlogger = logging.getLogger()\nlogger.addHandler(log_handler)\n\n# Works with simple log messages like:\nlogger.info('Some useful information...')\n\n# Can also handle extra fields:\nlogger.warning('You\\'ve been warned!', extra={'foo': 'bar'})\n\n# And, of course, captures exception with full stack-trace\ntry:\n 1/0\nexcept Exception as exc:\n logger.error('Ooops!', exc_info=exc)\n```\n\nThese 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:\n\n```json\n[\n {\n \"type\": \"async-http-logging\",\n \"created\": 1610393068.365492,\n \"relative_created\": 1505.5122375488281,\n \"message\": \"Some useful information...\",\n \"level\": {\n \"number\": 20,\n \"name\": \"INFO\"\n },\n \"stack_trace\": null,\n \"sourcecode\": {\n \"pathname\": \"/path/to/your/python/script.py\",\n \"function\": \"function_name\",\n \"line\": 123\n },\n \"process\": {\n \"id\": 1234,\n \"name\": \"MainProcess\"\n },\n \"thread\": {\n \"id\": 1234567890,\n \"name\": \"MainThread\"\n }\n },\n {\n \"type\": \"async-http-logging\",\n \"created\": 1610393068.3663092,\n \"relative_created\": 1506.3292980194092,\n \"message\": \"You've been warned!\",\n \"level\": {\n \"number\": 30,\n \"name\": \"WARNING\"\n },\n \"stack_trace\": null,\n \"sourcecode\": {\n \"pathname\": \"/path/to/your/python/script.py\",\n \"function\": \"function_name\",\n \"line\": 456\n },\n \"process\": {\n \"id\": 1234,\n \"name\": \"MainProcess\"\n },\n \"thread\": {\n \"id\": 1234567890,\n \"name\": \"MainThread\"\n }\n },\n {\n \"type\": \"async-http-logging\",\n \"created\": 1610393068.3663092,\n \"relative_created\": 1506.3292980194092,\n \"message\": \"Ooops!\",\n \"level\": {\n \"number\": 40,\n \"name\": \"ERROR\"\n },\n \"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\",\n \"sourcecode\": {\n \"pathname\": \"/path/to/your/python/script.py\",\n \"function\": \"function_name\",\n \"line\": 17\n },\n \"process\": {\n \"id\": 1234,\n \"name\": \"MainProcess\"\n },\n \"thread\": {\n \"id\": 1234567890,\n \"name\": \"MainThread\"\n }\n }\n]\n```\n\nIn your backend, you can funnel these logs to wherever suits you best: database, ElasticSearch index, third-party monitoring service, etc.\n\nLearn more about these and other features in the [project Wiki](https://github.com/hacktlib/py-async-http-logging/wiki).\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Non-blocking HTTP handler for Python `logging` with local SQLite buffer/cache.",
"version": "1.0.4",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "f9f6f38463ab9fa683839727abfa2c68",
"sha256": "82605ec5ed901a858b572e7544e32bbc6c2b13d49e0b23cd3ad22b293353cb42"
},
"downloads": -1,
"filename": "http_logging-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f9f6f38463ab9fa683839727abfa2c68",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6, <4",
"size": 11997,
"upload_time": "2021-01-18T01:28:11",
"upload_time_iso_8601": "2021-01-18T01:28:11.903468Z",
"url": "https://files.pythonhosted.org/packages/df/6f/3936c4b2c2a2b04ebfea4a7a580f7b9387581d4894a48b2dd3d115ff0e8e/http_logging-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-01-18 01:28:11",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "http-logging"
}