Created
July 16, 2014 16:04
-
-
Save unbit/7970e4faa5f5edc108ba to your computer and use it in GitHub Desktop.
uWSGI log encoder example
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
#include <uwsgi.h> | |
static char *log_encoder_add_worker(struct uwsgi_log_encoder *ule, char *msg, size_t len, size_t *rlen) { | |
char *buf = NULL; | |
// 64 bytes for worker id should be enough, btw the buffer will be adapted automatically | |
struct uwsgi_buffer *ub = uwsgi_buffer_new(len + 64); | |
// add current pid | |
if (uwsgi_buffer_num64(ub, getpid())) goto end; | |
// add a space | |
if (uwsgi_buffer_byte(ub, ' ')) goto end; | |
// append the original message | |
if (uwsgi_buffer_append(ub, msg, len)) goto end; | |
// set the size of the new string | |
*rlen = ub->pos; | |
// set the new log line | |
buf = ub->buf; | |
// avoid the memory to be destroyed | |
ub->buf = NULL; | |
end: | |
uwsgi_buffer_destroy(ub); | |
return buf; | |
} | |
static void myencoder_register() { | |
uwsgi_register_log_encoder("myencoder", log_encoder_add_worker); | |
} | |
struct uwsgi_plugin myencoder_plugin = { | |
.name = "myencoder", | |
.on_load = myencoder_register, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment