Skip to content
uWSGI plugin that creates custom json-escaped logging variables
C Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

uWSGI JSON logging plugin

uWSGI plugin that defines custom JSON-escaped logchunks json_uri and json_host. These logchunks can be used to configure JSON logging of requests. Problem with uWSGI JSON encoder is that logchunks can't be encoded as separate JSON fields. You can define custom text output that looks like JSON, but the problem is that string fields are not JSON escaped. This plugin solves that problem and escapes problematic logchunks.

Example of a uwsgi log format (ini file):

plugin =

logger-req = stdio
; json_uri and json_host are json-escaped fields defined in ``
log-format = "address":"%(addr)", "host":"%(json_host)", "method":"%(method)", "uri":"%(json_uri)", "protocol":"%(proto)", "resp_size":%(size), "req_body_size":%(cl), "resp_status":%(status), "resp_time":%(secs)
log-req-encoder = format {"time":"${micros}", "source":"uwsgi-req", ${msg}}
log-req-encoder = nl

And a resulting log record:

{"time": 1580765438.767256, "source": "uwsgi-req", "address": "", "host": "", "method": "GET", "uri": "/authorize", "protocol": "HTTP/1.0", "resp_size": 120, "req_body_size": 0, "resp_status": 200, "resp_time": 0.000524}

Very short official documentation on registering new logchunks, used as a starting point for this code:

Tested with uWSGI version 2.0.18.

Usage example

You must have uWSGI installed to build and use this plugin:

Build plugin

uwsgi --build-plugin escape_json.c

or use bash script:


Run uWSGI with plugin

uwsgi --plugin ...

Or you can reference plugin in your ini config file:

plugin =

Ivan Borko, Velebit AI

You can’t perform that action at this time.