Merge pull request #4288 from aldelaro5/reduce-logged-filename

Reduce the filepath of logs
This commit is contained in:
shuffle2 2016-10-04 17:39:25 -07:00 committed by GitHub
commit 5d3853d854
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();