-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug.c
89 lines (70 loc) · 1.64 KB
/
debug.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
//#include <syslog.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "debug.h"
#define STD_BUF 1024
#ifdef DEBUG
int loglevel = LOG_ALL;
char *DebugMessageFile = NULL;
int DebugMessageLine = 0;
int GetLogLevel(void)
{
static int log_init = 0;
static unsigned int log_level = 0;
// declared here for compatibility with older compilers
// not initialized here cuz the next step is done once
const char* key;
if (log_init)
return log_level;
key = getenv(LOG_VARIABLE);
if (key)
log_level = strtoul(key, NULL, 0);
else
log_level = 0;
log_init = 1;
return log_level;
}
void LogMessage(int level, char *fmt, ...)
{
va_list ap;
int log_level = GetLogLevel();
if ( !(level & log_level) )
return;
va_start(ap, fmt);
if (0) //(snort_conf != NULL) && ScDaemonMode())
{
char buf[STD_BUF];
int buf_len = sizeof(buf);
char *buf_ptr = buf;
buf[buf_len - 1] = '\0';
/* filename and line number information */
if ((log_level > LOG_DEBUG) &&
(DebugMessageFile != NULL))
{
snprintf(buf, buf_len - 1, "%s:%d: ",
DebugMessageFile, DebugMessageLine);
buf_ptr += strlen(buf);
buf_len -= strlen(buf);
}
vsnprintf(buf_ptr, buf_len - 1, fmt, ap);
// syslog(LOG_DAEMON | LOG_DEBUG, "%s", buf);
}
else
{
if ((log_level > LOG_DEBUG) &&
(DebugMessageFile != NULL))
printf("%s:%d: ", DebugMessageFile, DebugMessageLine);
vprintf(fmt, ap);
}
va_end(ap);
}
#else
void LogMessage(int level, char *fmt, ...)
{
}
#endif /* DEBUG */