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
|
// TODO general logging overhaul. make sure messages make sense, are consistent, etc.
// TODO make this not rely on so many globals.
// TODO colorize stdout for easier reading
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <syslog.h>
#include "net.h"
extern bool quiet;
extern bool daemonize;
extern bool remote_logging;
extern bool use_syslog;
extern bool log_to_file;
extern FILE *outfilep;
extern sock_t sock;
// output logs according to runtime configuration
void output(const char *msg) {
if (!daemonize) {
if (!quiet) {
printf("%s\n", msg);
}
}
if (remote_logging) {
sockprintf(sock, "%s\r\n", msg);
}
if (log_to_file) {
fprintf(outfilep, "%s\n", msg);
}
}
// Display/log runtime messages
void msg(const char *fmt, ...) {
char buf[8192] = {0};
va_list vl;
va_start(vl, fmt);
vsnprintf(buf, sizeof(buf), fmt, vl);
va_end(vl);
if (use_syslog) {
syslog(LOG_INFO | LOG_USER, "%s", buf);
}
if (!daemonize) {
printf("%s\n", buf);
}
}
|