Logo
~Sockets~
~Examples~
~Contact~


Debug.cpp

Go to the documentation of this file.
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", // &n */
00013                 "\x1B[0;0m\x1B[31m", // &r */
00014                 "\x1B[0;0m\x1B[32m", // &g */
00015                 "\x1B[0;0m\x1B[33m", // &y */
00016                 "\x1B[0;0m\x1B[34m", // &b */
00017                 "\x1B[0;0m\x1B[35m", // &m */
00018                 "\x1B[0;0m\x1B[36m", // &c */
00019                 "\x1B[0;0m\x1B[37m", // &w */
00020                 "\x1B[0;0m\x1B[30m", // &l */
00021                 "\x1B[1;31m", // &R */
00022                 "\x1B[1;32m", // &G */
00023                 "\x1B[1;33m", // &Y */
00024                 "\x1B[1;34m", // &B */
00025                 "\x1B[1;35m", // &M */
00026                 "\x1B[1;36m", // &C */
00027                 "\x1B[1;37m", // &W */
00028                 "\x1B[1;30m" }; // &L */
00029 
00030 
00031 
00032 void Debug::Print(const char *format, ...)
00033 {
00034         char slask[5000]; // temporary for vsprintf / vsnprintf
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 } // namespace SOCKETS_NAMESPACE {
00056 #endif
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4