forked from jordansissel/grok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grok_logging.c
37 lines (33 loc) · 1.1 KB
/
grok_logging.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
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
#include "grok.h"
#ifndef NOLOGGING
inline void _grok_log(int level, int indent, const char *format, ...) {
va_list args;
FILE *out;
out = stderr;
va_start(args, format);
char *prefix;
/* TODO(sissel): use gperf instead of this silly switch */
switch (level) {
case LOG_CAPTURE: prefix = "[capture] "; break;
case LOG_COMPILE: prefix = "[compile] "; break;
case LOG_EXEC: prefix = "[exec] "; break;
case LOG_MATCH: prefix = "[match] "; break;
case LOG_PATTERNS: prefix = "[patterns] "; break;
case LOG_PREDICATE: prefix = "[predicate] "; break;
case LOG_PROGRAM: prefix = "[program] "; break;
case LOG_PROGRAMINPUT: prefix = "[programinput] "; break;
case LOG_REACTION: prefix = "[reaction] "; break;
case LOG_REGEXPAND: prefix = "[regexpand] "; break;
case LOG_DISCOVER: prefix = "[discover] "; break;
default: prefix = "[unknown] ";
}
fprintf(out, "[%d] %*s%s", getpid(), indent * 2, "", prefix);
vfprintf(out, format, args);
fprintf(out, "\n");
va_end(args);
}
#endif