# logbook-logstash
JSON logs with logstash format for logbook
This library is provided to allow [logbook](http://pythonhosted.org/Logbook/) logging to output log data
as json objects ready to be shipped out to logstash.
This project is a fork of [exoscale/python-logstash-formatter](https://github.com/exoscale/python-logstash-formatter)
## Installing
Pip:
$ pip install logbook-logstash
Pypi:
https://pypi.python.org/pypi/logbook-logstash
Manual:
$ python setup.py install
## Usage
Json outputs are provided by the LogstashFormatter logging formatter, for instance:
```python
import sys
import logbook_logstash
from logbook import Logger, StreamHandler
log = Logger('testlog')
handler = StreamHandler(sys.stdout)
handler.formatter = logbook_logstash.LogstashFormatter()
handler.push_application()
log.info('My test')
```
```python
logger.info({"account": 123, "ip": "172.20.19.18"})
logger.info("classic message for account: %s", account, extra={"account": account})
try:
h = {}
h['key']
except:
logger.info("something unexpected happened", exc_info=True)
```
## Sample output
The following keys will be found in the output JSON:
* ``@source_host``: source hostname for the log
* ``@timestamp``: ISO 8601 timestamp
* ``@message``: short message for this log
* ``@fields``: all extra fields
```python
{
"@fields": {
"account": "pyr",
"args": [],
"created": 1367480388.013037,
"exception": [
"Traceback (most recent call last):\n",
" File \"toto.py\", line 16, in <module>\n k['unknown']\n",
"KeyError: 'unknown'\n"
],
"filename": "toto.py",
"funcName": "<module>",
"levelname": "WARNING",
"levelno": 30,
"lineno": 18,
"module": "toto",
"msecs": 13.036966323852539,
"name": "root",
"pathname": "toto.py",
"process": 1819,
"processName": "MainProcess",
"relativeCreated": 18.002986907958984,
"thread": 140060726359808,
"threadName": "MainThread"
},
"@message": "TOTO",
"@source_host": "phoenix.spootnik.org",
"@timestamp": "2013-05-02T09:39:48.013158"
}
```
PyPI 官网下载 | logbook-logstash-0.1.2.tar.gz
版权申诉
186 浏览量
2022-02-10
14:30:16
上传
评论
收藏 3KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
- 092300108.cpp
- 车类型数据集6000张VOC+YOLO格式.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈