Add support for debug messages

Add new DEBUG_LOG macro for debug messages. The messages are enabled
when compiled with --enable-debug and they are printed when the -d
option is used twice.
This commit is contained in:
Miroslav Lichvar
2013-11-26 18:53:10 +01:00
parent 0731cd6950
commit 4bbc5520b8
6 changed files with 42 additions and 5 deletions

View File

@@ -39,6 +39,11 @@
#define FORMAT_ATTRIBUTE_PRINTF(str, first)
#endif
#define DEBUG_LOG(facility, ...) \
do { \
if (DEBUG) \
LOG_Message(LOGS_DEBUG, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__); \
} while (0)
#define LOG(severity, facility, ...) LOG_Message(severity, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__)
#define LOG_FATAL(facility, ...) LOG_Message(LOGS_FATAL, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__)
@@ -47,7 +52,8 @@ typedef enum {
LOGS_INFO,
LOGS_WARN,
LOGS_ERR,
LOGS_FATAL
LOGS_FATAL,
LOGS_DEBUG
} LOG_Severity;
/* Definition of facility. Each message is tagged with who generated
@@ -95,6 +101,9 @@ extern void LOG_Message(LOG_Severity severity, LOG_Facility facility,
int line_number, const char *filename,
const char *function_name, const char *format, ...);
/* Enable logging of debug messages */
extern void LOG_EnableDebug(void);
/* Log messages to syslog instead of stderr */
extern void LOG_OpenSystemLog(void);