Skip to content

IaroslavR/structlog-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT Code style: black Python: 3.6

Simple wrapper for CLI script which can use all advantages of structlog and can work with modules which use old good standard lib logging as well

Q Why I need it?
A Write Logs for Machines, use JSON and dev friendly console output without logging setup boilerplate

Usage

By default script behave like a proper 12 factor app that outputs only JSON to stdout and leave the logs of libraries that use logging unchanged

python ./examples/app.py

Boom!!!! advent=2018-11-01 00:00:01
Bang! advent=2018-11-01 00:00:01
Wow, exception  advent=2018-11-01 00:00:01
Traceback (most recent call last):
  File "/home/mirror/PycharmProjects/structlog-boilerplate/examples/libs/sdt_lib.py", line 14, in f
    1 / 0
ZeroDivisionError: division by zero
{'advent': '2018-11-01 00:00:01', 'event': 'Boom!!!!', 'logger': 'libs.structlog_lib', 'level': 'critical', 'timestamp': '2018-11-03T15:37:59.006392Z'}
{'advent': '2018-11-01 00:00:01', 'event': 'Bang!', 'logger': 'libs.structlog_lib', 'level': 'error', 'timestamp': '2018-11-03T15:37:59.006509Z'}
{'advent': '2018-11-01 00:00:01', 'event': 'Wow, exception', 'logger': 'libs.structlog_lib', 'level': 'error', 'timestamp': '2018-11-03T15:37:59.006650Z', 'exception': 'Traceback (most recent call last):\n  File "/home/mirror/PycharmProjects/structlog-boilerplate/examples/libs/structlog_lib.py", line 15, in f\n    1 / 0\nZeroDivisionError: division by zero'}
{"event": "result", "timestamp": "2018-11-03T15:37:59.006884Z", "value": 42}

But if verbosity level escalates, script produces developer friendly colored output

python ./examples/app.py -vv

colored output