blob: 779fa4b86739ea3a14a6425c8c8d95b8f8f53d5f (
plain)
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
|
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include "log.h"
#include "misc.h"
void vprintlog(log_output output_type, int priority, const char *fmt, va_list args) {
char *buf = calloc(vformat_len_copy(fmt, args)+1, sizeof(char));
vsprintf(buf, fmt, args);
switch (output_type) {
case LOG_OUT_SYSLOG: {
syslog(priority, "%s", buf);
break;
}
case LOG_OUT_STDERR:
case LOG_OUT_STDOUT: {
FILE *output = (output_type == LOG_OUT_STDOUT) ? stdout : stderr;
fprintf(output, "%s\n", buf);
break;
}
default:
break;
}
free(buf);
}
void printlog(log_output output_type, int priority, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
vprintlog(output_type, priority, fmt, args);
va_end(args);
}
|