-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlog.c
49 lines (37 loc) · 739 Bytes
/
log.c
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
/* Copyright (c) 2019 by Erik Larsson
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <syslog.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
static int do_syslog = 0;
static int loglevel = LOG_WARNING;
void setup_syslog() {
openlog(NULL, LOG_NOWAIT, LOG_DAEMON);
setlogmask(loglevel);
do_syslog = 1;
}
void set_loglevel(int prio) {
loglevel = prio;
}
void agent_log(int prio, const char *format, ...) {
va_list ap;
va_start(ap, format);
if (prio > loglevel) {
return;
}
switch (do_syslog) {
case 0:
vdprintf(2, format, ap);
dprintf(2, "\n");
break;
case 1:
vsyslog(prio, format, ap);
break;
}
va_end(ap);
if (prio == LOG_CRIT) {
exit(1);
}
}