Post your logs to an API — python
Oct 11, 2023
TLDR; We’ll be creating a custom log handler in python that posts your log messages to an API
Although we can simply post log messages to an API using python’s requests module, the idea here is to use a single logger that logs to stdout, a log file, and your API.
- StreamHandler for stdout
- FileHandler to log to a file
- RequestsHandler to log to an API
Will be writing a bonus snippet to mute log output to stdout when a field name ‘silent’ is set to true in the extra={} dict passed to the log statement.
Hope this helps!
I’ll see you in the next article!
Until then, here’s something irrelevant: