00001 #include "Debug.h"
00002 #include <stdarg.h>
00003
00004
00005 #ifdef SOCKETS_NAMESPACE
00006 namespace SOCKETS_NAMESPACE {
00007 #endif
00008
00009
00010 std::map<unsigned long, int> Debug::m_level;
00011 const char *Debug::colors[] = {
00012 "\x1B[0;0m",
00013 "\x1B[0;0m\x1B[31m",
00014 "\x1B[0;0m\x1B[32m",
00015 "\x1B[0;0m\x1B[33m",
00016 "\x1B[0;0m\x1B[34m",
00017 "\x1B[0;0m\x1B[35m",
00018 "\x1B[0;0m\x1B[36m",
00019 "\x1B[0;0m\x1B[37m",
00020 "\x1B[0;0m\x1B[30m",
00021 "\x1B[1;31m",
00022 "\x1B[1;32m",
00023 "\x1B[1;33m",
00024 "\x1B[1;34m",
00025 "\x1B[1;35m",
00026 "\x1B[1;36m",
00027 "\x1B[1;37m",
00028 "\x1B[1;30m" };
00029
00030
00031
00032 void Debug::Print(const char *format, ...)
00033 {
00034 char slask[5000];
00035 va_list ap;
00036
00037 va_start(ap, format);
00038 #ifdef _WIN32
00039 vsprintf(slask, format, ap);
00040 #else
00041 vsnprintf(slask, 5000, format, ap);
00042 #endif
00043 va_end(ap);
00044
00045 fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]);
00046 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00047 fprintf(stderr, " ");
00048 if (slask[strlen(slask) - 1] == '\n')
00049 slask[strlen(slask) - 1] = 0;
00050 fprintf(stderr, "%s%s\n", slask, colors[0]);
00051 }
00052
00053
00054 #ifdef SOCKETS_NAMESPACE
00055 }
00056 #endif