tp_utils.cpp 1.11 KB
Newer Older
Francois Tessier's avatar
Francois Tessier committed
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
#include "tp_utils.hpp"
#include <stdarg.h> 

void printMsg ( msg_t type, char* format, ... ) {
  va_list args;
  va_start(args, format);
  
  char message[1024];
  vsprintf ( message, format, args );
  
  switch ( type )
    {
    case ERROR:
#ifdef COLOR
      fprintf ( stderr, RED "[ERR]" RESET " %s", message);
#else
      fprintf ( stderr, "[ERR] %s", message);
#endif
      break;
    case WARNING:
#ifdef COLOR
      fprintf ( stdout, YELLOW "[WARN]" RESET " %s", message);
#else
      fprintf ( stdout, "[WARN] %s", message);
#endif
      break;
    case INFO:
#ifdef COLOR
      fprintf ( stdout, GREEN "[INFO]" RESET " %s", message);
#else
      fprintf ( stdout, "[INFO] %s", message);
#endif
      break;
    case TIMING:
35
#ifdef TIMING
Francois Tessier's avatar
Francois Tessier committed
36 37 38 39
#ifdef COLOR
      fprintf ( stdout, BLUE "[TIME]" RESET " %s", message);
#else
      fprintf ( stdout, "[TIME] %s", message);
40 41 42 43 44 45 46 47 48 49
#endif
#endif
      break;
    case DEBUG:
#ifdef DBG
#ifdef COLOR
      fprintf ( stdout, MAGENTA "[DEBUG]" RESET " %s", message);
#else
      fprintf ( stdout, "[ERR] %s", message);
#endif
Francois Tessier's avatar
Francois Tessier committed
50 51 52 53 54 55 56 57
#endif
      break;
    default:
      break;
    }

  va_end (args);
}