00001 #include "Debug.h"
00002 #include <stdarg.h>
00003 #include <cstring>
00004
00005
00006 #ifdef SOCKETS_NAMESPACE
00007 namespace SOCKETS_NAMESPACE {
00008 #endif
00009
00010
00011 std::map<unsigned long, int> Debug::m_level;
00012 const char *Debug::colors[] = {
00013 "\x1B[0;0m",
00014 "\x1B[0;0m\x1B[31m",
00015 "\x1B[0;0m\x1B[32m",
00016 "\x1B[0;0m\x1B[33m",
00017 "\x1B[0;0m\x1B[34m",
00018 "\x1B[0;0m\x1B[35m",
00019 "\x1B[0;0m\x1B[36m",
00020 "\x1B[0;0m\x1B[37m",
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
00029
00030 void Debug::Print(const char *format, ...)
00031 {
00032 char slask[5000];
00033 va_list ap;
00034
00035 va_start(ap, format);
00036 #ifdef _WIN32
00037 vsprintf(slask, format, ap);
00038 #else
00039 vsnprintf(slask, 5000, format, ap);
00040 #endif
00041 va_end(ap);
00042
00043 fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00044 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00045 fprintf(stderr, " ");
00046 if (slask[strlen(slask) - 1] == '\n')
00047 slask[strlen(slask) - 1] = 0;
00048 fprintf(stderr, "%s%s\n", slask, colors[0]);
00049 }
00050
00051
00052 Debug& Debug::operator<<(const std::string& str)
00053 {
00054 m_line += str;
00055 return *this;
00056 }
00057
00058
00059 Debug& Debug::operator<<(long l)
00060 {
00061 m_line += Utility::l2string(l);
00062 return *this;
00063 }
00064
00065
00066 Debug& Debug::operator<<(endl)
00067 {
00068 Print("%s", m_line.c_str());
00069 m_line = "";
00070 return *this;
00071 }
00072
00073
00074 #ifdef SOCKETS_NAMESPACE
00075 }
00076 #endif
00077