Skip to content

Instantly share code, notes, and snippets.

@alertedsnake
Last active May 26, 2020 18:58
Show Gist options
  • Save alertedsnake/e13de246ab2facff0b7648a186c37c0e to your computer and use it in GitHub Desktop.
Save alertedsnake/e13de246ab2facff0b7648a186c37c0e to your computer and use it in GitHub Desktop.
Uwsgi logs in JSON format
# add 'logfile' to the plugin list
plugins = python3,logfile
# match logs already in json format
logger = applogger stdio
log-route = applogger ^{
log-encoder = format:applogger ${msg}
log-encoder = nl:applogger
# all other logs, we jsonify
logger = default stdio
log-route = default ^(?!\{)
log-encoder = json:default {"timestamp":"${strftime:%%Y-%%m-%%dT%%H:%%M:%%S}", "source":"uwsgi", "levelname":"INFO", "message":"${msg}"}
log-encoder = nl:default
@alertedsnake
Copy link
Author

It should be noted that this still won't do all logs - you'll get a few startup messages before the logging kicks in, which look like this:

[uWSGI] getting INI configuration from uwsgi.ini
[log-encoder] registered format:applogger ${msg}
[log-encoder] registered json:default {"timestamp":"${strftime:%Y-%m-%dT%H:%M:%S}", "source":"uwsgi", levelname:"INFO", "message":"${msg}"}
[log-encoder] registered nl:default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment