summaryrefslogtreecommitdiff
path: root/example.py
blob: 0892117fa8c75b6e3af7cd2a02a2bc06a8bbb522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python3
import json
import logging

import logformat
import requests


logfmt_handler = logging.StreamHandler()
logfmt_handler.setFormatter(logformat.LogfmtFormatter())
logging.basicConfig(handlers=[logfmt_handler], level=logging.DEBUG)


logger = logformat.get_logger()

requests.get('http://example.com')

logger.debug("what's happening")
logger.info("something's happening")
logger.warning("this seems off", some_id=33)
logger.error("oh no")

try:
    json.loads("maybe")
except:
    logger.error("failed to decode", traceback=True)