tp_utils.cpp 934 Bytes
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 35 36 37 38 39 40 41 42 43 44 45 46
#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:
#ifdef COLOR
      fprintf ( stdout, BLUE "[TIME]" RESET " %s", message);
#else
      fprintf ( stdout, "[TIME] %s", message);
#endif
      break;
    default:
      break;
    }

  va_end (args);
}