add support in logger to disable display of date/time optionally during log initialization;

2.0-maint
Bryan Biedenkapp 3 years ago
parent 16ba6c5e99
commit cfc86169e9

@ -71,6 +71,7 @@ static FILE* m_fpLog = NULL;
static FILE* m_actFpLog = NULL; static FILE* m_actFpLog = NULL;
static uint32_t m_displayLevel = 2U; static uint32_t m_displayLevel = 2U;
static bool m_disableTimeDisplay = false;
static struct tm m_tm; static struct tm m_tm;
static struct tm m_actTm; static struct tm m_actTm;
@ -248,12 +249,14 @@ void ActivityLog(const char *mode, const bool sourceRf, const char* msg, ...)
/// <param name="fileRoot">Prefix of the detailed log file name.</param> /// <param name="fileRoot">Prefix of the detailed log file name.</param>
/// <param name="fileLevel">File logging level.</param> /// <param name="fileLevel">File logging level.</param>
/// <param name="displayLevel">Console logging level.</param> /// <param name="displayLevel">Console logging level.</param>
bool LogInitialise(const std::string& filePath, const std::string& fileRoot, uint32_t fileLevel, uint32_t displayLevel) /// <param name="disableTimeDisplay">Disable display of date/time on the console log.</param>
bool LogInitialise(const std::string& filePath, const std::string& fileRoot, uint32_t fileLevel, uint32_t displayLevel, bool disableTimeDisplay)
{ {
m_filePath = filePath; m_filePath = filePath;
m_fileRoot = fileRoot; m_fileRoot = fileRoot;
m_fileLevel = fileLevel; m_fileLevel = fileLevel;
m_displayLevel = displayLevel; m_displayLevel = displayLevel;
m_disableTimeDisplay = disableTimeDisplay;
return ::LogOpen(); return ::LogOpen();
} }
@ -278,26 +281,46 @@ void Log(uint32_t level, const char *module, const char* fmt, ...)
char buffer[501U]; char buffer[501U];
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
SYSTEMTIME st; if (!m_disableTimeDisplay) {
::GetSystemTime(&st); SYSTEMTIME st;
::GetSystemTime(&st);
if (module != NULL) { if (module != NULL) {
::sprintf(buffer, "%c: %04u-%02u-%02u %02u:%02u:%02u.%03u (%s) ", LEVELS[level], st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, module); ::sprintf(buffer, "%c: %04u-%02u-%02u %02u:%02u:%02u.%03u (%s) ", LEVELS[level], st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, module);
} }
else {
::sprintf(buffer, "%c: %04u-%02u-%02u %02u:%02u:%02u.%03u ", LEVELS[level], st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
}
}
else { else {
::sprintf(buffer, "%c: %04u-%02u-%02u %02u:%02u:%02u.%03u ", LEVELS[level], st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); if (module != NULL) {
::sprintf(buffer, "%c: (%s) ", LEVELS[level], module);
}
else {
::sprintf(buffer, "%c: ", LEVELS[level]);
}
} }
#else #else
struct timeval now; if (!m_disableTimeDisplay) {
::gettimeofday(&now, NULL); struct timeval now;
::gettimeofday(&now, NULL);
struct tm* tm = ::gmtime(&now.tv_sec); struct tm* tm = ::gmtime(&now.tv_sec);
if (module != NULL) { if (module != NULL) {
::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03lu (%s) ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000U, module); ::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03lu (%s) ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000U, module);
} }
else {
::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03lu ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000U);
}
}
else { else {
::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03lu ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000U); if (module != NULL) {
::sprintf(buffer, "%c: (%s) ", LEVELS[level], module);
}
else {
::sprintf(buffer, "%c: ", LEVELS[level]);
}
} }
#endif #endif

@ -76,7 +76,7 @@ extern HOST_SW_API void ActivityLogFinalise();
extern HOST_SW_API void ActivityLog(const char* mode, const bool sourceRf, const char* msg, ...); extern HOST_SW_API void ActivityLog(const char* mode, const bool sourceRf, const char* msg, ...);
/// <summary>Initializes the diagnostics log.</summary> /// <summary>Initializes the diagnostics log.</summary>
extern HOST_SW_API bool LogInitialise(const std::string& filePath, const std::string& fileRoot, uint32_t fileLevel, uint32_t displayLevel); extern HOST_SW_API bool LogInitialise(const std::string& filePath, const std::string& fileRoot, uint32_t fileLevel, uint32_t displayLevel, bool disableTimeDisplay = false);
/// <summary>Finalizes the diagnostics log.</summary> /// <summary>Finalizes the diagnostics log.</summary>
extern HOST_SW_API void LogFinalise(); extern HOST_SW_API void LogFinalise();
/// <summary>Writes a new entry to the diagnostics log.</summary> /// <summary>Writes a new entry to the diagnostics log.</summary>

Loading…
Cancel
Save

Powered by TurnKey Linux.