dprintf.h 2.62 KB
#ifndef __DPRINTF_H__
#define __DPRINTF_H__

/* A macro DEBUG_LEVEL determina o nivel de debugging
 * A seguinte regra eh utilizada:
 *
 * DEBUG_LEVEL >= 3: Apenas DDDPRINTF serah compilada.
 * DEBUG_LEVEL >= 2: DDDPRINTF E DDPRINTF serao compiladas.
 * DEBUG_LEVEL >= 1: DDDPRINTF, DDPRINTF e DPRINTF serao compiladas.
 * DEBUG_LEVEL == 0: Nada sera compilado. */

#include <stdio.h>

/* tamanho maximo (em bytes) do arquivo de log (1M) */
//#define TAMANHO_MAXIMO_LOG 1048576
#define TAMANHO_MAXIMO_LOG 5242880

 #define _DPRINTF_ERROR    "\033[30m"
 #define _DPRINTF_WARN     "\033[33m"
 #define _DPRINTF_INFO     "\033[32m"
 #define _DPRINTF_FAIL     "\033[31m"
 #define _DPRINTF_END      "\033[0m"

#define _DPRINTF_NOP(format, ...)    do { } while (0)

#ifdef DEBUG_LEVEL

 #if DEBUG_LEVEL & 4
  #define DDDPRINTF(format, ...) {                                    \
   fprintf(stderr,                                                    \
           _DPRINTF_ERROR"%s::%s [%d] -> "_DPRINTF_END format,      \
           __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__);         \
	} 

 #else          /* !DEBUG_LEVEL > 2 */
  #define DDDPRINTF    _DPRINTF_NOP
 #endif         /* DEBUG_LEVEL > 2 */

 #if DEBUG_LEVEL & 2
  #define DDPRINTF(format, ...) {                                     \
   fprintf(stderr,                                                    \
           _DPRINTF_WARN"%s::%s [%d] -> "_DPRINTF_END format,       \
           __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__);         \
	}

#else          /* !DEBUG_LEVEL > 1 */
  #define DDPRINTF    _DPRINTF_NOP
 #endif         /* DEBUG_LEVEL > 1 */

 #if DEBUG_LEVEL & 1
  #define DPRINTF(format, ...) {                                      \
   fprintf(stderr,                                                    \
           _DPRINTF_INFO"%s::%s [%d] -> "_DPRINTF_END format,       \
           __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__);         \
	}

 #else          /* !DEBUG_LEVEL > 0 */
  #define DPRINTF    _DPRINTF_NOP
 #endif         /* DEBUG_LEVEL > 0 */

 #if DEBUG_LEVEL & 1
  #define DDDDPRINTF(format, ...) {                                      \
   fprintf(stderr,                                                    \
           _DPRINTF_FAIL"%s::%s [%d] -> "_DPRINTF_END format,       \
           __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__);         \
	}

 #else          /* !DEBUG_LEVEL > 0 */
  #define DDDDPRINTF    _DPRINTF_NOP
 #endif         /* DEBUG_LEVEL > 0 */	

#else           /* DEBUG_LEVEL */
 #define DPRINTF      _DPRINTF_NOP
 #define DDPRINTF     _DPRINTF_NOP
 #define DDDPRINTF    _DPRINTF_NOP
#endif  /* ! DEBUG_LEVEL */

#endif  /* __DPRINTF_H__ */