From b71f808cb87dc3f8518ee1c436b582485ed8480c Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sun, 18 Jan 2015 02:43:11 -0600 Subject: [PATCH] Gut some more debug functions --- common/debug.cpp | 191 +---------------------------------------------- common/debug.h | 5 +- 2 files changed, 2 insertions(+), 194 deletions(-) diff --git a/common/debug.cpp b/common/debug.cpp index 7dbd28751..6f5426927 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -80,193 +80,4 @@ EQEmuLog::~EQEmuLog() fclose(fp[i]); } } -} - -bool EQEmuLog::open(LogIDs id) -{ - if (!logFileValid) { - return false; - } - if (id >= MaxLogID) { - return false; - } - LockMutex lock(&MOpen); - if (pLogStatus[id] & 4) { - return false; - } - if (fp[id]) { - //cerr<<"Warning: LogFile already open"<= MaxLogID) { - return false; - } - - bool dofile = false; - if (pLogStatus[id] & 1) { - dofile = open(id); - } - if (!(dofile || pLogStatus[id] & 2)) { - return false; - } - LockMutex lock(&MLog[id]); - if (!logFileValid) { - return false; //check again for threading race reasons (to avoid two mutexes) - } - - va_list argptr, tmpargptr; - va_start(argptr, fmt); - - // Log.Log(id, vStringFormat(fmt, argptr).c_str()); - - return true; -} - -//write with Prefix and a VA_list -bool EQEmuLog::writePVA(LogIDs id, const char *prefix, const char *fmt, va_list argptr) -{ - if (!logFileValid) { - return false; - } - if (id >= MaxLogID) { - return false; - } - bool dofile = false; - if (pLogStatus[id] & 1) { - dofile = open(id); - } - if (!(dofile || pLogStatus[id] & 2)) { - return false; - } - LockMutex lock(&MLog[id]); - if (!logFileValid) { - return false; //check again for threading race reasons (to avoid two mutexes) - } - time_t aclock; - struct tm *newtime; - time( &aclock ); /* Get time in seconds */ - newtime = localtime( &aclock ); /* Convert time to struct */ - va_list tmpargptr; - if (dofile) { - #ifndef NO_PIDLOG - fprintf(fp[id], "[%02d.%02d. - %02d:%02d:%02d] %s", newtime->tm_mon + 1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec, prefix); - #else - fprintf(fp[id], "%04i [%02d.%02d. - %02d:%02d:%02d] %s", getpid(), newtime->tm_mon + 1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec, prefix); - #endif - va_copy(tmpargptr, argptr); - vfprintf( fp[id], fmt, tmpargptr ); - } - if (pLogStatus[id] & 2) { - if (pLogStatus[id] & 8) { - fprintf(stderr, "[%s] %s", LogNames[id], prefix); - vfprintf( stderr, fmt, argptr ); - } - /* Console Output */ - else { - - -#ifdef _WINDOWS - HANDLE console_handle; - console_handle = GetStdHandle(STD_OUTPUT_HANDLE); - - CONSOLE_FONT_INFOEX info = { 0 }; - info.cbSize = sizeof(info); - info.dwFontSize.Y = 12; // leave X as zero - info.FontWeight = FW_NORMAL; - wcscpy(info.FaceName, L"Lucida Console"); - SetCurrentConsoleFontEx(console_handle, NULL, &info); - - if (id == EQEmuLog::LogIDs::Status){ SetConsoleTextAttribute(console_handle, ConsoleColor::Colors::Yellow); } - if (id == EQEmuLog::LogIDs::Error){ SetConsoleTextAttribute(console_handle, ConsoleColor::Colors::LightRed); } - if (id == EQEmuLog::LogIDs::Normal){ SetConsoleTextAttribute(console_handle, ConsoleColor::Colors::LightGreen); } - if (id == EQEmuLog::LogIDs::Debug){ SetConsoleTextAttribute(console_handle, ConsoleColor::Colors::Yellow); } - if (id == EQEmuLog::LogIDs::Quest){ SetConsoleTextAttribute(console_handle, ConsoleColor::Colors::LightCyan); } - if (id == EQEmuLog::LogIDs::Commands){ SetConsoleTextAttribute(console_handle, ConsoleColor::Colors::LightMagenta); } - if (id == EQEmuLog::LogIDs::Crash){ SetConsoleTextAttribute(console_handle, ConsoleColor::Colors::LightRed); } -#endif - - fprintf(stdout, "[%s] %s", LogNames[id], prefix); - vfprintf(stdout, fmt, argptr); - -#ifdef _WINDOWS - /* Always set back to white*/ - SetConsoleTextAttribute(console_handle, ConsoleColor::Colors::White); -#endif - } - } - va_end(argptr); - if (dofile) { - fprintf(fp[id], "\n"); - } - if (pLogStatus[id] & 2) { - if (pLogStatus[id] & 8) { - fprintf(stderr, "\n"); - } else { - fprintf(stdout, "\n"); - } - } - if (dofile) { - fflush(fp[id]); - } - return true; -} - -bool EQEmuLog::writeNTS(LogIDs id, bool dofile, const char *fmt, ...) -{ - va_list argptr, tmpargptr; - va_start(argptr, fmt); - if (dofile) { - va_copy(tmpargptr, argptr); - vfprintf( fp[id], fmt, tmpargptr ); - } - if (pLogStatus[id] & 2) { - if (pLogStatus[id] & 8) { - vfprintf( stderr, fmt, argptr ); - } else { - vfprintf( stdout, fmt, argptr ); - } - } - va_end(argptr); - return true; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/common/debug.h b/common/debug.h index 5c32eadce..0a1ab0fc3 100644 --- a/common/debug.h +++ b/common/debug.h @@ -91,11 +91,8 @@ public: MaxLogID /* Max, used in functions to get the max log ID */ }; - bool write(LogIDs id, const char *fmt, ...); - bool writePVA(LogIDs id, const char *prefix, const char *fmt, va_list args); + private: - bool open(LogIDs id); - bool writeNTS(LogIDs id, bool dofile, const char *fmt, ...); // no error checking, assumes is open, no locking, no timestamp, no newline Mutex MOpen; Mutex MLog[MaxLogID];