| 1 |
/*
|
| 2 |
debug.h: log (or not) messages using syslog
|
| 3 |
Copyright (C) 2003 Ludovic Rousseau
|
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify
|
| 6 |
it under the terms of the GNU General Public License as published by
|
| 7 |
the Free Software Foundation; either version 2 of the License, or
|
| 8 |
(at your option) any later version.
|
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful,
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
GNU General Public License for more details.
|
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License
|
| 16 |
along with this program; if not, write to the Free Software
|
| 17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
*/
|
| 19 |
|
| 20 |
/*
|
| 21 |
* $Id$
|
| 22 |
*/
|
| 23 |
|
| 24 |
/*
|
| 25 |
* DEBUG_CRITICAL("text");
|
| 26 |
* print "text" is DEBUG_LEVEL_CRITICAL and DEBUG_STDERR is defined
|
| 27 |
* send "text" to syslog if DEBUG_LEVEL_CRITICAL is defined
|
| 28 |
*
|
| 29 |
* DEBUG_CRITICAL2("text: %d", 1234)
|
| 30 |
* print "text: 1234" is DEBUG_LEVEL_CRITICAL and DEBUG_STDERR is defined
|
| 31 |
* send "text: 1234" to syslog if DEBUG_LEVEL_CRITICAL is defined
|
| 32 |
* the format string can be anything printf() can understand
|
| 33 |
*
|
| 34 |
* same thing for DEBUG_INFO and DEBUG_COMM
|
| 35 |
*
|
| 36 |
* DEBUG_XXD(msg, buffer, size) is only defined if DEBUG_LEVEL_COMM if defined
|
| 37 |
*
|
| 38 |
*/
|
| 39 |
|
| 40 |
#ifndef __CONFIG_H__
|
| 41 |
#error "file config.h NOT included"
|
| 42 |
#endif
|
| 43 |
|
| 44 |
#ifndef _GCDEBUG_H_
|
| 45 |
#define _GCDEBUG_H_
|
| 46 |
|
| 47 |
#ifdef DEBUG_LEVEL_CRITICAL
|
| 48 |
#define DEBUG_CRITICAL(fmt) debug_msg("%s:%d " fmt, __FILE__, __LINE__)
|
| 49 |
#define DEBUG_CRITICAL2(fmt, data) debug_msg("%s:%d " fmt, __FILE__, __LINE__, data)
|
| 50 |
#define DEBUG_CRITICAL3(fmt, data1, data2) debug_msg("%s:%d " fmt, __FILE__, __LINE__, data1, data2)
|
| 51 |
#define DEBUG
|
| 52 |
#else
|
| 53 |
#define DEBUG_CRITICAL(fmt)
|
| 54 |
#define DEBUG_CRITICAL2(fmt, data)
|
| 55 |
#define DEBUG_CRITICAL3(fmt, data1, data2)
|
| 56 |
#endif
|
| 57 |
|
| 58 |
#ifdef DEBUG_LEVEL_INFO
|
| 59 |
#define DEBUG_INFO(fmt) debug_msg("%s:%d " fmt, __FILE__, __LINE__)
|
| 60 |
#define DEBUG_INFO2(fmt, data) debug_msg("%s:%d " fmt, __FILE__, __LINE__, data)
|
| 61 |
#define DEBUG_INFO3(fmt, data1, data2) debug_msg("%s:%d " fmt, __FILE__, __LINE__, data1, data2)
|
| 62 |
#define DEBUG_INFO4(fmt, data1, data2, data3) debug_msg("%s:%d " fmt, __FILE__, __LINE__, data1, data2, data3)
|
| 63 |
#define DEBUG
|
| 64 |
#else
|
| 65 |
#define DEBUG_INFO(fmt)
|
| 66 |
#define DEBUG_INFO2(fmt, data)
|
| 67 |
#define DEBUG_INFO3(fmt, data1, data2)
|
| 68 |
#define DEBUG_INFO4(fmt, data1, data2, data3)
|
| 69 |
#endif
|
| 70 |
|
| 71 |
#ifdef DEBUG_LEVEL_PERIODIC
|
| 72 |
#define DEBUG_PERIODIC(fmt) debug_msg("%s:%d " fmt, __FILE__, __LINE__)
|
| 73 |
#define DEBUG_PERIODIC2(fmt, data) debug_msg("%s:%d " fmt, __FILE__, __LINE__, data)
|
| 74 |
#define DEBUG
|
| 75 |
#else
|
| 76 |
#define DEBUG_PERIODIC(fmt)
|
| 77 |
#define DEBUG_PERIODIC2(fmt, data)
|
| 78 |
#endif
|
| 79 |
|
| 80 |
#ifdef DEBUG_LEVEL_COMM
|
| 81 |
#define DEBUG_COMM(fmt) debug_msg("%s:%d " fmt, __FILE__, __LINE__)
|
| 82 |
#define DEBUG_COMM2(fmt, data) debug_msg("%s:%d " fmt, __FILE__, __LINE__, data)
|
| 83 |
#define DEBUG_COMM3(fmt, data1, data2) debug_msg("%s:%d " fmt, __FILE__, __LINE__, data1, data2)
|
| 84 |
#define DEBUG
|
| 85 |
#define DEBUG_XXD(msg, buffer, size) debug_xxd(msg, buffer, size)
|
| 86 |
#else
|
| 87 |
#define DEBUG_COMM(fmt)
|
| 88 |
#define DEBUG_COMM2(fmt, data)
|
| 89 |
#define DEBUG_COMM3(fmt, data1, data2)
|
| 90 |
#endif
|
| 91 |
|
| 92 |
#ifndef DEBUG_XXD
|
| 93 |
#define DEBUG_XXD(msg, buffer, size)
|
| 94 |
#endif
|
| 95 |
|
| 96 |
void debug_msg(char *fmt, ...);
|
| 97 |
void debug_xxd(const char *msg, const unsigned char *buffer, const int size);
|
| 98 |
|
| 99 |
#endif
|
| 100 |
|