1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include "../../uwsgi.h"
#include <systemd/sd-journal.h>
ssize_t uwsgi_systemd_logger(struct uwsgi_logger *ul, char *message, size_t len) {
// split multiline log messages to multiple journal lines
size_t i;
char *base = message;
for(i=0;i<len;i++) {
if (message[i] == '\n') {
message[i] = 0;
sd_journal_print(LOG_INFO, "%s", base);
base = message+i+1;
}
}
// last \n is missing...
if (base < message+len) {
sd_journal_print(LOG_INFO, "%.*s", (int) ((message+len) - base), base);
}
return 0;
}
void uwsgi_systemd_logger_register() {
uwsgi_register_logger("systemd", uwsgi_systemd_logger);
}
struct uwsgi_plugin systemd_logger_plugin = {
.name = "systemd_logger",
.on_load = uwsgi_systemd_logger_register,
};
|