mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-23 00:35:53 +08:00
Introducing RotateLog configuration option that allows disabling timestamps on the logfiles.
This commit is contained in:
15
Log.cpp
15
Log.cpp
@@ -41,6 +41,8 @@ static bool m_daemon = false;
|
||||
|
||||
static unsigned int m_displayLevel = 2U;
|
||||
|
||||
static unsigned int m_rotateLogs = 1U;
|
||||
|
||||
static struct tm m_tm;
|
||||
|
||||
static char LEVELS[] = " DMIWEF";
|
||||
@@ -66,10 +68,16 @@ static bool LogOpen()
|
||||
}
|
||||
|
||||
char filename[200U];
|
||||
char timestamp[37U] = "";
|
||||
|
||||
if (m_rotateLogs) {
|
||||
::sprintf(timestamp, "-%04d-%02d-%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
::sprintf(filename, "%s\\%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
||||
::sprintf(filename, "%s\\%s%s.log", m_filePath.c_str(), m_fileRoot.c_str(), timestamp);
|
||||
#else
|
||||
::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
||||
::sprintf(filename, "%s/%s%s.log", m_filePath.c_str(), m_fileRoot.c_str(), timestamp);
|
||||
#endif
|
||||
|
||||
if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) {
|
||||
@@ -86,12 +94,13 @@ static bool LogOpen()
|
||||
return status;
|
||||
}
|
||||
|
||||
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel)
|
||||
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int rotateLogs)
|
||||
{
|
||||
m_filePath = filePath;
|
||||
m_fileRoot = fileRoot;
|
||||
m_fileLevel = fileLevel;
|
||||
m_displayLevel = displayLevel;
|
||||
m_rotateLogs = rotateLogs;
|
||||
m_daemon = daemon;
|
||||
|
||||
if (m_daemon)
|
||||
|
||||
Reference in New Issue
Block a user