added port window and port range options
[anytun.git] / Sockets / Debug.cpp
blobce4bad696e811501cc0ec60155b4367c43e7008a
1 #include "Debug.h"
2 #include <stdarg.h>
5 #ifdef SOCKETS_NAMESPACE
6 namespace SOCKETS_NAMESPACE {
7 #endif
10 std::map<unsigned long, int> Debug::m_level;
11 const char *Debug::colors[] = {
12 "\x1B[0;0m", // &n */
13 "\x1B[0;0m\x1B[31m", // &r */
14 "\x1B[0;0m\x1B[32m", // &g */
15 "\x1B[0;0m\x1B[33m", // &y */
16 "\x1B[0;0m\x1B[34m", // &b */
17 "\x1B[0;0m\x1B[35m", // &m */
18 "\x1B[0;0m\x1B[36m", // &c */
19 "\x1B[0;0m\x1B[37m", // &w */
20 "\x1B[0;0m\x1B[30m", // &l */
21 "\x1B[1;31m", // &R */
22 "\x1B[1;32m", // &G */
23 "\x1B[1;33m", // &Y */
24 "\x1B[1;34m", // &B */
25 "\x1B[1;35m", // &M */
26 "\x1B[1;36m", // &C */
27 "\x1B[1;37m", // &W */
28 "\x1B[1;30m" }; // &L */
32 void Debug::Print(const char *format, ...)
34 char slask[5000]; // temporary for vsprintf / vsnprintf
35 va_list ap;
37 va_start(ap, format);
38 #ifdef _WIN32
39 vsprintf(slask, format, ap);
40 #else
41 vsnprintf(slask, 5000, format, ap);
42 #endif
43 va_end(ap);
45 fprintf(stderr, "%s", colors[Utility::ThreadID() % 16 + 1]);
46 for (int i = 0; i < m_level[Utility::ThreadID()]; i++)
47 fprintf(stderr, " ");
48 if (slask[strlen(slask) - 1] == '\n')
49 slask[strlen(slask) - 1] = 0;
50 fprintf(stderr, "%s%s\n", slask, colors[0]);
54 Debug& Debug::operator<<(const std::string& str)
56 m_line += str;
57 return *this;
61 Debug& Debug::operator<<(long l)
63 m_line += Utility::l2string(l);
64 return *this;
68 Debug& Debug::operator<<(endl)
70 Print("%s", m_line.c_str());
71 m_line = "";
72 return *this;
76 #ifdef SOCKETS_NAMESPACE
77 } // namespace SOCKETS_NAMESPACE {
78 #endif