1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Respect logging time-stamp config.

This commit is contained in:
Sandu Liviu Catalin 2021-02-03 22:08:32 +02:00
parent 70a5eaa5d1
commit c8e5012642
2 changed files with 7 additions and 9 deletions

View File

@ -167,7 +167,7 @@ static inline void OutputConsoleMessage(const Logger::MsgPtr & msg)
CONSOLE_SCREEN_BUFFER_INFO csb_state; CONSOLE_SCREEN_BUFFER_INFO csb_state;
GetConsoleScreenBufferInfo(hstdout, &csb_state); GetConsoleScreenBufferInfo(hstdout, &csb_state);
SetConsoleTextAttribute(hstdout, GetLevelColor(msg->mLvl)); SetConsoleTextAttribute(hstdout, GetLevelColor(msg->mLvl));
if (msg->mTms) if (Logger::Get().ConsoleHasTime())
{ {
std::printf("%s %s ", GetLevelTag(msg->mLvl), msg->mBuf); std::printf("%s %s ", GetLevelTag(msg->mLvl), msg->mBuf);
} }
@ -179,7 +179,7 @@ static inline void OutputConsoleMessage(const Logger::MsgPtr & msg)
std::printf("%s\n", msg->mStr.c_str()); std::printf("%s\n", msg->mStr.c_str());
SetConsoleTextAttribute(hstdout, csb_state.wAttributes); SetConsoleTextAttribute(hstdout, csb_state.wAttributes);
#else #else
if (msg->mTms) if (Logger::Get().ConsoleHasTime())
{ {
std::printf("%s %s %s\033[0m\n", std::printf("%s %s %s\033[0m\n",
msg->mSub ? GetColoredLevelTagDim(msg->mLvl) : GetColoredLevelTag(msg->mLvl), msg->mBuf, msg->mStr.c_str()); msg->mSub ? GetColoredLevelTagDim(msg->mLvl) : GetColoredLevelTag(msg->mLvl), msg->mBuf, msg->mStr.c_str());
@ -532,8 +532,6 @@ void Logger::ProcessMessage()
return; return;
} }
} }
// Override time-stamp requirements
m_Message->mTms = (m_ConsoleTime || m_LogFileTime);
// Are we allowed to send this message level to console? // Are we allowed to send this message level to console?
if (m_ConsoleLevels & m_Message->mLvl) if (m_ConsoleLevels & m_Message->mLvl)
{ {
@ -546,7 +544,7 @@ void Logger::ProcessMessage()
std::fputs(GetLevelTag(m_Message->mLvl), m_File); std::fputs(GetLevelTag(m_Message->mLvl), m_File);
std::fputc(' ', m_File); std::fputc(' ', m_File);
// Should we include the time-stamp? // Should we include the time-stamp?
if (m_Message->mTms) if (m_LogFileTime)
{ {
std::fputs(m_Message->mBuf, m_File); std::fputs(m_Message->mBuf, m_File);
std::fputc(' ', m_File); std::fputc(' ', m_File);

View File

@ -52,7 +52,7 @@ protected:
uint8_t mLvl; // Message level. uint8_t mLvl; // Message level.
uint8_t mInc; // Message increments. uint8_t mInc; // Message increments.
bool mSub; // Message hierarchy. bool mSub; // Message hierarchy.
bool mTms; // Message hierarchy. bool mTms; // Message time-stamp.
char mBuf[TMS_LEN]; // Message time-stamp. char mBuf[TMS_LEN]; // Message time-stamp.
/* ---------------------------------------------------------------------------------------- /* ----------------------------------------------------------------------------------------
* Default constructor. * Default constructor.
@ -155,8 +155,8 @@ private:
MsgQueue m_Queue; // Queue of messages outside of main thread. MsgQueue m_Queue; // Queue of messages outside of main thread.
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
uint8_t m_ConsoleLevels; // The levels allowed to be outputted to console. uint8_t m_ConsoleLevels; // The levels allowed to be outputted to console.
uint8_t m_LogFileLevels; // The levels allowed to be outputted to log file. uint8_t m_LogFileLevels; // The levels allowed to be outputted to log file.
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
bool m_ConsoleTime; // Whether console messages should be timestamped. bool m_ConsoleTime; // Whether console messages should be timestamped.
@ -164,7 +164,7 @@ private:
bool m_CyclicLock; // Prevent the script callback from entering a loop. bool m_CyclicLock; // Prevent the script callback from entering a loop.
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
uint32_t m_StringTruncate; // The length at which to truncate strings in debug. uint32_t m_StringTruncate; // The length at which to truncate strings in debug.
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
std::FILE* m_File; // Handle to the file where the logs should be saved. std::FILE* m_File; // Handle to the file where the logs should be saved.