forked from redBorder/rb_monitor
/
rb_log.c
71 lines (62 loc) · 1.83 KB
/
rb_log.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
/*
** Copyright (C) 2014 Eneo Tecnologia S.L.
** Author: Eugenio Perez <eupm90@gmail.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License Version 2 as
** published by the Free Software Foundation. You may not use, modify or
** distribute this program under any other version of the GNU General
** Public License.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "rb_log.h"
static int debug_level=-1;
static int debug_flags=0;
void Log0(const char * file,int line,const int level,char *fmt,...){
assert(file);
assert(line);
if(level >= debug_level)
return;
if(debug_flags != 0){
va_list ap;
if(debug_flags & DEBUG_STDOUT)
{
va_start(ap, fmt);
switch(level){
case LOG_EMERG:
case LOG_ALERT:
case LOG_CRIT:
case LOG_ERR:
case LOG_WARNING:
fprintf(stderr, "%s:%d->",file,line);
vfprintf(stderr, fmt, ap);
break;
case LOG_NOTICE:
case LOG_INFO:
case LOG_DEBUG:
fprintf(stdout, "%s:%d->",file,line);
vfprintf(stdout, fmt, ap);
break;
};
va_end(ap);
}
if(debug_flags & DEBUG_SYSLOG)
{
va_start(ap, fmt);
vsyslog(level, fmt, ap);
va_end(ap);
}
}
}
// Return the current debug level of worker_info
void debug_set_debug_level(int level){debug_level = level;}
// Set the output flags
void debug_set_output_flags(int flags){debug_flags = flags;}