00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "Debug.h"
00032 #include <stdarg.h>
00033 #include <cstring>
00034
00035
00036 #ifdef SOCKETS_NAMESPACE
00037 namespace SOCKETS_NAMESPACE {
00038 #endif
00039
00040
00041 std::map<unsigned long, int> Debug::m_level;
00042 const char *Debug::colors[] = {
00043 "\x1B[0;0m",
00044 "\x1B[0;0m\x1B[31m",
00045 "\x1B[0;0m\x1B[32m",
00046 "\x1B[0;0m\x1B[33m",
00047 "\x1B[0;0m\x1B[34m",
00048 "\x1B[0;0m\x1B[35m",
00049 "\x1B[0;0m\x1B[36m",
00050 "\x1B[0;0m\x1B[37m",
00051 "\x1B[1;31m",
00052 "\x1B[1;32m",
00053 "\x1B[1;33m",
00054 "\x1B[1;34m",
00055 "\x1B[1;35m",
00056 "\x1B[1;36m",
00057 "\x1B[1;37m" };
00058
00059
00060 void Debug::Print(const char *format, ...)
00061 {
00062 char slask[5000];
00063 va_list ap;
00064
00065 va_start(ap, format);
00066 vsnprintf(slask, sizeof(slask), format, ap);
00067 va_end(ap);
00068
00069 fprintf(stderr, "%s", colors[Utility::ThreadID() % 14 + 1]);
00070 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
00071 fprintf(stderr, " ");
00072 if (slask[strlen(slask) - 1] == '\n')
00073 slask[strlen(slask) - 1] = 0;
00074 fprintf(stderr, "%s%s\n", slask, colors[0]);
00075 }
00076
00077
00078 Debug& Debug::operator<<(const char * str)
00079 {
00080 m_line += str;
00081 return *this;
00082 }
00083
00084
00085 Debug& Debug::operator<<(const std::string& str)
00086 {
00087 m_line += str;
00088 return *this;
00089 }
00090
00091
00092 Debug& Debug::operator<<(short l)
00093 {
00094 m_line += Utility::l2string(l);
00095 return *this;
00096 }
00097
00098
00099 Debug& Debug::operator<<(int l)
00100 {
00101 m_line += Utility::l2string(l);
00102 return *this;
00103 }
00104
00105
00106 Debug& Debug::operator<<(long l)
00107 {
00108 m_line += Utility::l2string(l);
00109 return *this;
00110 }
00111
00112
00113 Debug& Debug::operator<<(double d)
00114 {
00115 char slask[100];
00116 snprintf(slask, sizeof(slask), "%f", d);
00117 m_line += slask;
00118 return *this;
00119 }
00120
00121
00122 Debug& Debug::operator<<(endl)
00123 {
00124 Print("%s", m_line.c_str());
00125 m_line = "";
00126 return *this;
00127 }
00128
00129
00130 #ifdef SOCKETS_NAMESPACE
00131 }
00132 #endif
00133