-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add user info in uwsgi request logs
Refs KER-367
- Loading branch information
Showing
3 changed files
with
70 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
https://github.com/velebit-ai/uwsgi-json-logging-plugin/blob/4edb5cc59013b18f32658195b328afb2ac21b2d2/escape_json.c | ||
uWSGI plugin that creates custom json-escaped logging variables. | ||
build plugin with `uwsgi --build-plugin <filename.c>` | ||
and use it with `uwsgi --plugin <filename_plugin.so> ...` | ||
*/ | ||
#include <uwsgi.h> | ||
|
||
|
||
static ssize_t uwsgi_lf_json_uri(struct wsgi_request *wsgi_req, char **buf) { | ||
long pos = offsetof(struct wsgi_request, uri); | ||
long pos_len = offsetof(struct wsgi_request, uri_len); | ||
char **var = (char **) (((char *) wsgi_req) + pos); | ||
uint16_t *varlen = (uint16_t *) (((char *) wsgi_req) + pos_len); | ||
|
||
char *e_json = uwsgi_malloc((*varlen * 2) + 1); | ||
escape_json(*var, *varlen, e_json); | ||
*buf = e_json; | ||
return strlen(*buf); | ||
} | ||
|
||
static ssize_t uwsgi_lf_json_host(struct wsgi_request *wsgi_req, char **buf) { | ||
long pos = offsetof(struct wsgi_request, host); | ||
long pos_len = offsetof(struct wsgi_request, host_len); | ||
char **var = (char **) (((char *) wsgi_req) + pos); | ||
uint16_t *varlen = (uint16_t *) (((char *) wsgi_req) + pos_len); | ||
|
||
char *e_json = uwsgi_malloc((*varlen * 2) + 1); | ||
escape_json(*var, *varlen, e_json); | ||
*buf = e_json; | ||
return strlen(*buf); | ||
} | ||
|
||
static void register_logchunks() { | ||
uwsgi_register_logchunk("json_uri", uwsgi_lf_json_uri, 1); | ||
uwsgi_register_logchunk("json_host", uwsgi_lf_json_host, 1); | ||
} | ||
|
||
struct uwsgi_plugin escape_json_plugin = { | ||
.name = "escape_json", | ||
.on_load = register_logchunks, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters