From ad594abe6963a79f91f0116accd98feed0816782 Mon Sep 17 00:00:00 2001 From: nakeee Date: Sun, 3 Jan 2010 08:48:48 +0000 Subject: [PATCH] Adding line and file name to the log. This makes the log line a bit too long in my taste so if anyone got an idea of how to make it look nicer i.e making it optional or adding it only to errors/warnings do share git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4776 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/Log.h | 5 +++-- Source/Core/Common/Src/LogManager.cpp | 16 ++++++++-------- Source/Core/Common/Src/LogManager.h | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Source/Core/Common/Src/Log.h b/Source/Core/Common/Src/Log.h index ac79e2e24e..2ca5bb10c6 100644 --- a/Source/Core/Common/Src/Log.h +++ b/Source/Core/Common/Src/Log.h @@ -105,14 +105,15 @@ enum LOG_LEVELS { #define INFO_LOG(...) {} #define DEBUG_LOG(...) {} -void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char *fmt, ...); +void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, + const char *file, int line, const char *fmt, ...); #ifdef GEKKO #define GENERIC_LOG(t, v, ...) #else // Let the compiler optimize this out -#define GENERIC_LOG(t, v, ...) {if (v <= MAX_LOGLEVEL) {GenericLog(v, t, __VA_ARGS__);}} +#define GENERIC_LOG(t, v, ...) {if (v <= MAX_LOGLEVEL) {GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__);}} #endif #if MAX_LOGLEVEL >= ERROR_LEVEL diff --git a/Source/Core/Common/Src/LogManager.cpp b/Source/Core/Common/Src/LogManager.cpp index 8af3d103c6..199a0cf4f0 100644 --- a/Source/Core/Common/Src/LogManager.cpp +++ b/Source/Core/Common/Src/LogManager.cpp @@ -17,12 +17,12 @@ #include "LogManager.h" #include "Timer.h" - -void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* fmt, ...) +void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, + const char *file, int line, const char* fmt, ...) { va_list args; va_start(args, fmt); - LogManager::GetInstance()->Log(level, type, fmt, args); + LogManager::GetInstance()->Log(level, type, file, line, fmt, args); va_end(args); } @@ -95,7 +95,8 @@ LogManager::~LogManager() { } void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, - const char *format, va_list args) { + const char *file, int line, const char *format, + va_list args) { char temp[MAX_MSGLEN]; char msg[MAX_MSGLEN + 512]; @@ -107,11 +108,10 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, CharArrayFromFormatV(temp, MAX_MSGLEN, format, args); static const char level_to_char[7] = "-NEWID"; - sprintf(msg, "%s %c[%s]: %s\n", + sprintf(msg, "%s %s:%u %c[%s]: %s\n", Common::Timer::GetTimeFormatted().c_str(), - level_to_char[(int)level], - log->getShortName(), - temp); + file, line, level_to_char[(int)level], + log->getShortName(), temp); logMutex.Enter(); log->trigger(level, msg); diff --git a/Source/Core/Common/Src/LogManager.h b/Source/Core/Common/Src/LogManager.h index 232bf6901f..780c9b826c 100644 --- a/Source/Core/Common/Src/LogManager.h +++ b/Source/Core/Common/Src/LogManager.h @@ -143,7 +143,7 @@ public: static u32 GetMaxLevel() { return MAX_LOGLEVEL; } void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, - const char *fmt, va_list args); + const char *file, int line, const char *fmt, va_list args); void setLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) { m_Log[type]->setLevel(level);