Get proxy working. sort of.
[shim.git] / log.c
blobaf00af74cee93d8374552d9932a68aba39755f46
1 #include <stdio.h>
2 #include "log.h"
4 static enum log_level min_log_level = LOG_NOTICE;
5 static FILE *log_file = NULL;
7 void
8 log_debug(const char *msg, ...)
10 va_list ap;
12 va_start(ap, msg);
13 log_msg_va(LOG_DEBUG, msg, ap);
14 va_end(ap);
17 void
18 log_info(const char *msg, ...)
20 va_list ap;
22 va_start(ap, msg);
23 log_msg_va(LOG_INFO, msg, ap);
24 va_end(ap);
27 void
28 log_notice(const char *msg, ...)
30 va_list ap;
32 va_start(ap, msg);
33 log_msg_va(LOG_NOTICE, msg, ap);
34 va_end(ap);
37 void
38 log_warn(const char *msg, ...)
40 va_list ap;
42 va_start(ap, msg);
43 log_msg_va(LOG_WARN, msg, ap);
44 va_end(ap);
47 void
48 log_error(const char *msg, ...)
50 va_list ap;
52 va_start(ap, msg);
53 log_msg_va(LOG_ERROR, msg, ap);
54 va_end(ap);
57 void
58 log_fatal(const char *msg, ...)
60 va_list ap;
62 va_start(ap, msg);
63 log_msg_va(LOG_FATAL, msg, ap);
64 va_end(ap);
67 void
68 log_msg_va(enum log_level lvl, const char *msg, va_list ap)
70 if (lvl >= min_log_level) {
71 vfprintf(log_file, msg, ap);
72 fputs("\n", log_file);
73 fflush(log_file);
77 void
78 log_set_min_level(enum log_level lvl)
80 min_log_level = lvl;
83 enum log_level
84 log_get_min_level(void)
86 return min_log_level;
89 void
90 log_set_file(FILE *fp)
92 if (!fp)
93 log_file = stderr;
94 else
95 log_file = fp;