generated from daniil-berg/boilerplate-py
added code and readme contents
This commit is contained in:
@@ -1,10 +1,56 @@
|
||||
# syslogformat
|
||||
|
||||
Python logging.Formatter class for syslog style messages
|
||||
Python `logging.Formatter` class for syslog style messages
|
||||
|
||||
## Usage
|
||||
|
||||
...
|
||||
Example with in-code setup:
|
||||
```python
|
||||
# example.py
|
||||
import logging
|
||||
from syslogformat import SyslogFormatter
|
||||
|
||||
log = logging.getLogger()
|
||||
hdl = logging.StreamHandler()
|
||||
fmt = SyslogFormatter()
|
||||
hdl.setFormatter(fmt)
|
||||
hdl.setLevel(logging.NOTSET)
|
||||
log.addHandler(hdl)
|
||||
log.setLevel(logging.NOTSET)
|
||||
|
||||
log.debug("foo")
|
||||
log.info("bar")
|
||||
log.warning("baz")
|
||||
try:
|
||||
raise ValueError("this is bad")
|
||||
except ValueError as e:
|
||||
log.exception("oh no")
|
||||
```
|
||||
|
||||
This is what the output should be like:
|
||||
```
|
||||
<7>DEBUG | foo
|
||||
<6>INFO | bar
|
||||
<4>WARNING | baz | example.<module>.14
|
||||
<3>ERROR | oh no | example.<module>.18 | 'Traceback (most recent call last):\n File "/path/to/example.py", line 16, in <module>\n raise ValueError("this is bad")\nValueError: this is bad'
|
||||
```
|
||||
|
||||
Same configuration with YAML file to be loaded into `logging.config.dictConfig`:
|
||||
```yaml
|
||||
version: 1
|
||||
formatters:
|
||||
custom:
|
||||
(): syslogformat.SyslogFormatter
|
||||
handlers:
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
level: NOTSET
|
||||
formatter: custom
|
||||
stream: ext://sys.stdout
|
||||
root:
|
||||
level: NOTSET
|
||||
handlers: [console]
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -12,7 +58,7 @@ Python logging.Formatter class for syslog style messages
|
||||
|
||||
## Dependencies
|
||||
|
||||
Python Version ..., OS ...
|
||||
Python Version 3
|
||||
|
||||
## Building from source
|
||||
|
||||
|
||||
Reference in New Issue
Block a user