-
Notifications
You must be signed in to change notification settings - Fork 36
/
log.c
73 lines (64 loc) · 1.26 KB
/
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
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
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "chaosvpn.h"
void
log_init(int *argc, char ***argv, int logopt, int logfac)
{
#ifndef WIN32
char *progname;
progname = (progname = strrchr((*argv)[0], '/')) ? progname+1 : (*argv)[0];
openlog(progname, logopt, logfac);
#endif
}
void
log_raw(int priority, const char *format, ...)
{
char *prefix;
FILE *out;
va_list args;
out=stderr;
switch (priority) {
case LOG_EMERG:
prefix="<EMERG>";
break;
case LOG_ALERT:
prefix="<ALERT>";
break;
case LOG_ERR:
prefix="<ERR> ";
break;
case LOG_WARNING:
prefix="<WARN> ";
break;
case LOG_NOTICE:
prefix="<NOTE> ";
out=stdout;
break;
case LOG_INFO:
prefix="<INFO> ";
out=stdout;
break;
case LOG_DEBUG:
prefix="<DEBUG>";
out=stdout;
break;
default:
prefix="<INFO> ";
out=stdout;
}
#ifndef WIN32
va_start(args, format);
vsyslog(priority, format, args);
va_end(args);
#endif
if (out) {
va_start(args, format);
(void)fprintf(out, "%s ", prefix);
(void)vfprintf(out, format, args);
if (format[strlen(format) - 1] != '\n') {
(void)fprintf(out, "\n");
}
va_end(args);
}
}