-
Notifications
You must be signed in to change notification settings - Fork 0
/
logwrapper.c
75 lines (67 loc) · 1.24 KB
/
logwrapper.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
73
74
75
#include <stdio.h>
#include <stdarg.h>
#include "log.h"
void init_log_wrapper(const char *name)
{
#ifndef PRIVATE_LOG_WRAPPER
openlog(name, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);
#endif
}
void logi(const char *format, ...)
{
va_list ap;
va_start(ap, format);
#ifndef PRIVATE_LOG_WRAPPER
vsyslog(LOG_INFO, format, ap);
#else
fprintf(stderr, "[I] ");
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
#endif
va_end(ap);
}
void logd(const char *format, ...)
{
va_list ap;
va_start(ap, format);
#ifndef PRIVATE_LOG_WRAPPER
vsyslog(LOG_DEBUG, format, ap);
#else
fprintf(stderr, "[D] ");
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
#endif
va_end(ap);
}
void logw(const char *format, ...)
{
va_list ap;
va_start(ap, format);
#ifndef PRIVATE_LOG_WRAPPER
vsyslog(LOG_WARNING, format, ap);
#else
fprintf(stderr, "[W] ");
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
#endif
va_end(ap);
}
void loge(const char *format, ...)
{
va_list ap;
va_start(ap, format);
#ifndef PRIVATE_LOG_WRAPPER
vsyslog(LOG_ERR, format, ap);
#else
fprintf(stderr, "[E] ");
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
#endif
va_end(ap);
}
void destroy_log_wrapper(void)
{
#ifndef PRIVATE_LOG_WRAPPER
closelog();
#endif
}