File: syslog_plugin.c

package info (click to toggle)
uwsgi 2.0.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,564 kB
  • sloc: ansic: 87,066; python: 7,004; 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 (115 lines) | stat: -rw-r--r-- 2,685 bytes parent folder | download | duplicates (8)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "../../uwsgi.h"

#include <syslog.h>

extern struct uwsgi_server uwsgi;

struct uwsgi_syslog_facility {
	const char *name;
	int facility;
};

struct uwsgi_syslog_facility usf[] = {

	{ "auth",       LOG_AUTH,       },
#ifdef LOG_AUTHPRIV
        { "authpriv",   LOG_AUTHPRIV,   },
#endif
        { "cron",       LOG_CRON,       },
        { "daemon",     LOG_DAEMON,     },
#ifdef LOG_FTP
        { "ftp",        LOG_FTP,        },
#endif
#ifdef LOG_INSTALL
        { "install",    LOG_INSTALL     },
#endif
        { "kern",       LOG_KERN,       },
        { "lpr",        LOG_LPR,        },
        { "mail",       LOG_MAIL,       },
#ifdef INTERNAL_MARK
        { "mark",       INTERNAL_MARK,  },      /* INTERNAL */
#endif
#ifdef LOG_NETINFO
        { "netinfo",    LOG_NETINFO,    },
#endif
#ifdef LOG_RAS
        { "ras",        LOG_RAS         },
#endif
#ifdef LOG_REMOTEAUTH
        { "remoteauth", LOG_REMOTEAUTH  },
#endif
        { "news",       LOG_NEWS,       },
        { "security",   LOG_AUTH        },      /* DEPRECATED */
        { "syslog",     LOG_SYSLOG,     },
        { "user",       LOG_USER,       },
        { "uucp",       LOG_UUCP,       },
        { "local0",     LOG_LOCAL0,     },
        { "local1",     LOG_LOCAL1,     },
        { "local2",     LOG_LOCAL2,     },
        { "local3",     LOG_LOCAL3,     },
        { "local4",     LOG_LOCAL4,     },
        { "local5",     LOG_LOCAL5,     },
        { "local6",     LOG_LOCAL6,     },
        { "local7",     LOG_LOCAL7,     },
#ifdef LOG_LAUNCHD
        { "launchd",    LOG_LAUNCHD     },
#endif
        { NULL,         -1,             }
};

ssize_t uwsgi_syslog_logger(struct uwsgi_logger *ul, char *message, size_t len) {

	char *syslog_opts;
	int facility = LOG_DAEMON;

	if (!ul->configured) {

        	setlinebuf(stderr);

        	if (ul->arg == NULL) {
                	syslog_opts = "uwsgi";
        	}
		else {
			char *colon = strchr(ul->arg, ',');
			if (colon) {
				struct uwsgi_syslog_facility *fn = usf;
				while(fn->name) {
					if (!strcmp(fn->name, colon+1)) {
						facility = fn->facility;
						break;
					}
					fn++;
				}
				syslog_opts = uwsgi_str(ul->arg);
				syslog_opts[colon-ul->arg] = 0;
			}
			else {
				syslog_opts = ul->arg;
			}
		}

        	openlog(syslog_opts, 0, facility);

		ul->configured = 1;
	}

#ifdef __APPLE__
	syslog(LOG_NOTICE, "%.*s", (int) len, message);
#else
	syslog(LOG_INFO, "%.*s", (int) len, message);
#endif
	return 0;

}

void uwsgi_syslog_register() {
	uwsgi_register_logger("syslog", uwsgi_syslog_logger);
}

struct uwsgi_plugin syslog_plugin = {

        .name = "syslog",
        .on_load = uwsgi_syslog_register,

};