summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraldelaro5 <aldelaro5@gmail.com>2016-10-04 03:36:36 -0400
committeraldelaro5 <aldelaro5@gmail.com>2016-10-04 16:34:26 -0400
commit6ee799ba7c562ffb5c1f8bb2f59cbb00aae02236 (patch)
tree07ecd81eb2a2564f00ab7c53e219b474e0a91baf
parent7b29b3c5711b5bdd41dd65f315f7bcb850637957 (diff)
Reduces the the filename of logs
Using cmake and GCC, logs would contain the full file path when logging making logs lines unnecessarily long. This is solved by just removing anything before "/Source/Core/" (where / is whatever your OS uses to separated directory).
-rw-r--r--Source/Core/Common/Logging/LogManager.cpp16
-rw-r--r--Source/Core/Common/Logging/LogManager.h1
2 files changed, 16 insertions, 1 deletions
diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp
index a24a0bbc9a..5d15998398 100644
--- a/Source/Core/Common/Logging/LogManager.cpp
+++ b/Source/Core/Common/Logging/LogManager.cpp
@@ -9,6 +9,7 @@
#include <set>
#include <string>
+#include "Common/CommonPaths.h"
#include "Common/FileUtil.h"
#include "Common/IniFile.h"
#include "Common/Logging/ConsoleListener.h"
@@ -29,6 +30,15 @@ void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char*
LogManager* LogManager::m_logManager = nullptr;
+static size_t DeterminePathCutOffPoint()
+{
+ constexpr const char* pattern = DIR_SEP "Source" DIR_SEP "Core" DIR_SEP;
+ size_t pos = std::string(__FILE__).find(pattern);
+ if (pos != std::string::npos)
+ return pos + strlen(pattern);
+ return 0;
+}
+
LogManager::LogManager()
{
// create log containers
@@ -102,6 +112,8 @@ LogManager::LogManager()
if (enable && write_console)
container->AddListener(LogListener::CONSOLE_LISTENER);
}
+
+ m_path_cutoff_point = DeterminePathCutOffPoint();
}
LogManager::~LogManager()
@@ -125,8 +137,10 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const
CharArrayFromFormatV(temp, MAX_MSGLEN, format, args);
+ const char* path_to_print = file + m_path_cutoff_point;
+
std::string msg = StringFromFormat(
- "%s %s:%u %c[%s]: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line,
+ "%s %s:%u %c[%s]: %s\n", Common::Timer::GetTimeFormatted().c_str(), path_to_print, line,
LogTypes::LOG_LEVEL_TO_CHAR[(int)level], log->GetShortName().c_str(), temp);
for (auto listener_id : *log)
diff --git a/Source/Core/Common/Logging/LogManager.h b/Source/Core/Common/Logging/LogManager.h
index 1c5081cf60..ea7f2d86a3 100644
--- a/Source/Core/Common/Logging/LogManager.h
+++ b/Source/Core/Common/Logging/LogManager.h
@@ -87,6 +87,7 @@ private:
LogContainer* m_Log[LogTypes::NUMBER_OF_LOGS];
static LogManager* m_logManager; // Singleton. Ugh.
std::array<LogListener*, LogListener::NUMBER_OF_LISTENERS> m_listeners;
+ size_t m_path_cutoff_point = 0;
LogManager();
~LogManager();