RSS Git Download  Clone
Raw Blame History
/*******************************************************************************
 *	Debug.h		Debug information and routines
 *			T.Barnaby,	BEAM Ltd,	2007-02-07
 *******************************************************************************
 */
#ifndef Debug_H
#define	Debug_H

#include <stdio.h>
#include <wchar.h>
#include <syslog.h>
#include <time.h>

#define	DBG_STD			0x000001
#define DBG_CMD			0x000002
#define DBG_EVENT		0x000004
#define DBG_HTTP		0x000008
#define DBG_RESOURCE		0x000100
#define	DBG_THREADS		0x001000
#define	DBG_MISC		0x010000

extern int	bdebug;

void hd8(void* data, int n);
void hd32(void* data, int n);
double getTime();
void setDebug(int debug);
void tprintf(int log, const char* fmt, ...);

pid_t gettid();

/// General debug functions
#if DEBUG
#define	dprintf(level, fmt, a...)       if((level) & bdebug) tprintf(1, fmt, ##a);
#else
#define	dprintf(level, fmt, a...)
#endif

/// Warnings and errors logging
#if DEBUG
#define	nprintf(fmt, a...)	{ syslog(LOG_NOTICE, fmt, ##a); if(DBG_STD & bdebug) tprintf(0, fmt, ##a); }
#define	wprintf(fmt, a...)	{ syslog(LOG_WARNING, fmt, ##a); if(DBG_STD & bdebug) tprintf(0, fmt, ##a); }
#define	eprintf(fmt, a...)	{ syslog(LOG_ERR, fmt, ##a); if(DBG_STD & bdebug) tprintf(0, fmt, ##a); }
#else
#define	nprintf(fmt, a...)	syslog(LOG_NOTICE, fmt, ##a)
#define	wprintf(fmt, a...)	syslog(LOG_WARNING, fmt, ##a)
#define	eprintf(fmt, a...)	syslog(LOG_ERR, fmt, ##a)
#endif

#endif