1 #ifndef _SOCKETS_Debug_H
2 #define _SOCKETS_Debug_H
4 #include "sockets-config.h"
10 #ifdef SOCKETS_NAMESPACE
11 namespace SOCKETS_NAMESPACE
{
17 static const char *colors
[];
20 Debug(const std::string
& x
) : m_id(0), m_text(x
) {
21 fprintf(stderr
, "%s", colors
[Utility::ThreadID() % 16 + 1]);
22 for (int i
= 0; i
< m_level
[Utility::ThreadID()]; i
++)
24 fprintf(stderr
, "%s%s\n", x
.c_str(), colors
[0]);
25 m_level
[Utility::ThreadID()]++;
27 Debug(int id
, const std::string
& x
) : m_id(id
), m_text(x
) {
28 fprintf(stderr
, "%s", colors
[Utility::ThreadID() % 16 + 1]);
29 for (int i
= 0; i
< m_level
[Utility::ThreadID()]; i
++)
31 fprintf(stderr
, "%d> %s%s\n", m_id
, x
.c_str(), colors
[0]);
32 m_level
[Utility::ThreadID()]++;
35 if (m_level
[Utility::ThreadID()])
36 m_level
[Utility::ThreadID()]--;
37 fprintf(stderr
, "%s", colors
[Utility::ThreadID() % 16 + 1]);
38 for (int i
= 0; i
< m_level
[Utility::ThreadID()]; i
++)
41 fprintf(stderr
, "%d> /%s%s\n", m_id
, m_text
.c_str(), colors
[0]);
43 fprintf(stderr
, "/%s%s\n", m_text
.c_str(), colors
[0]);
46 static void Print(const char *format
, ...);
51 static std::map
<unsigned long, int> m_level
;
55 #ifdef SOCKETS_NAMESPACE
56 } // namespace SOCKETS_NAMESPACE {
59 #endif // _SOCKETS_Debug_H