File: grok_logging.c

package info (click to toggle)
grok 1.20110708.1-4.3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,460 kB
  • sloc: ansic: 3,469; ruby: 987; makefile: 276; sh: 124; yacc: 106
file content (37 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (5)
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