File: systemd_logger.c

package info (click to toggle)
uwsgi 2.0.31-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,624 kB
  • sloc: ansic: 87,072; python: 7,010; cpp: 1,133; java: 708; perl: 678; sh: 585; ruby: 555; makefile: 148; xml: 130; cs: 121; objc: 37; php: 28; erlang: 20; javascript: 11
file content (36 lines) | stat: -rw-r--r-- 759 bytes parent folder | download | duplicates (6)
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,

};