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).
This commit is contained in:
aldelaro5 2016-10-04 03:36:36 -04:00
parent 7b29b3c571
commit 6ee799ba7c
2 changed files with 16 additions and 1 deletions

View File

@ -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)

View File

@ -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();