https://github.com/macbre/monolog-python
Python's logging formatter compatible with
https://github.com/macbre/monolog-python
Last synced: about 1 year ago
JSON representation
Python's logging formatter compatible with
- Host: GitHub
- URL: https://github.com/macbre/monolog-python
- Owner: macbre
- License: mit
- Created: 2015-12-11T18:55:57.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-03T10:41:06.000Z (over 10 years ago)
- Last Synced: 2025-05-06T23:15:31.660Z (about 1 year ago)
- Language: Python
- Homepage: https://github.com/macbre/monolog-utils
- Size: 6.84 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# monolog-python
Python's logging formatter compatible with monolog-utils. Works great with syslogng/elastic/kibana trio.
## Install
```
pip install monolog-python
```
## Example
```python
import logging
from monolog import MonologHandler
def fun():
return 2/0
logger = logging.getLogger('monolog.example')
logger.addHandler(MonologHandler()) # send message to a local syslog
try:
fun()
except ZeroDivisionError:
logger.error('fun() call raised an exception', exc_info=True, extra={'context': {'my_value': 3}}))
```
Or run:
```
$ python monolog/examples/example.py
```
```json
{
"@context": {
"exception": {
"class": "ZeroDivisionError",
"message": "integer division or modulo by zero",
"trace": [
" File \"monolog/examples/example.py\", line 32, in \n fun()\n",
" File \"monolog/examples/example.py\", line 7, in fun\n return 2/0\n"
]
},
"my_value": 3
},
"@fields": {
"filename": "example.py",
"lineno": 34
},
"@message": "fun() call raised an exception",
"@source_host": "debian",
"@timestamp": "2016-01-02T22:45:33.336",
"program": "monolog.example",
"severity": "error"
}
```