Revert "Merge pull request #648 from xfxian/logrotate"

This reverts commit 9932394840, reversing
changes made to cfc313e5b9.
This commit is contained in:
Jonathan Naylor 2020-10-30 13:34:13 +00:00
parent 9932394840
commit 61afb194c5
8 changed files with 7 additions and 28 deletions

1
.gitignore vendored
View file

@ -15,6 +15,5 @@ RemoteCommand
*.user *.user
*.VC.db *.VC.db
.vs .vs
.vscode
*.ambe *.ambe
GitVersion.h GitVersion.h

View file

@ -82,7 +82,6 @@ m_logDisplayLevel(0U),
m_logFileLevel(0U), m_logFileLevel(0U),
m_logFilePath(), m_logFilePath(),
m_logFileRoot(), m_logFileRoot(),
m_logTimestampLogs(1U),
m_cwIdEnabled(false), m_cwIdEnabled(false),
m_cwIdTime(10U), m_cwIdTime(10U),
m_cwIdCallsign(), m_cwIdCallsign(),
@ -454,8 +453,6 @@ bool CConf::read()
m_logFileLevel = (unsigned int)::atoi(value); m_logFileLevel = (unsigned int)::atoi(value);
else if (::strcmp(key, "DisplayLevel") == 0) else if (::strcmp(key, "DisplayLevel") == 0)
m_logDisplayLevel = (unsigned int)::atoi(value); m_logDisplayLevel = (unsigned int)::atoi(value);
else if (::strcmp(key, "TimestampLogs") == 0)
m_logTimestampLogs = (unsigned int)::atoi(value);
} else if (section == SECTION_CWID) { } else if (section == SECTION_CWID) {
if (::strcmp(key, "Enable") == 0) if (::strcmp(key, "Enable") == 0)
m_cwIdEnabled = ::atoi(value) == 1; m_cwIdEnabled = ::atoi(value) == 1;
@ -1077,11 +1074,6 @@ std::string CConf::getLogFileRoot() const
return m_logFileRoot; return m_logFileRoot;
} }
unsigned int CConf::getLogTimestampLogs() const
{
return m_logTimestampLogs;
}
bool CConf::getCWIdEnabled() const bool CConf::getCWIdEnabled() const
{ {
return m_cwIdEnabled; return m_cwIdEnabled;

2
Conf.h
View file

@ -54,7 +54,6 @@ public:
unsigned int getLogFileLevel() const; unsigned int getLogFileLevel() const;
std::string getLogFilePath() const; std::string getLogFilePath() const;
std::string getLogFileRoot() const; std::string getLogFileRoot() const;
unsigned int getLogTimestampLogs() const;
// The CW ID section // The CW ID section
bool getCWIdEnabled() const; bool getCWIdEnabled() const;
@ -338,7 +337,6 @@ private:
unsigned int m_logFileLevel; unsigned int m_logFileLevel;
std::string m_logFilePath; std::string m_logFilePath;
std::string m_logFileRoot; std::string m_logFileRoot;
unsigned int m_logTimestampLogs;
bool m_cwIdEnabled; bool m_cwIdEnabled;
unsigned int m_cwIdTime; unsigned int m_cwIdTime;

15
Log.cpp
View file

@ -41,8 +41,6 @@ static bool m_daemon = false;
static unsigned int m_displayLevel = 2U; static unsigned int m_displayLevel = 2U;
static unsigned int m_timestampLogs = 1U;
static struct tm m_tm; static struct tm m_tm;
static char LEVELS[] = " DMIWEF"; static char LEVELS[] = " DMIWEF";
@ -68,16 +66,10 @@ static bool LogOpen()
} }
char filename[200U]; char filename[200U];
char timestamp[37U] = "";
if (m_timestampLogs) {
::sprintf(timestamp, "-%04d-%02d-%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
}
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
::sprintf(filename, "%s\\%s%s.log", m_filePath.c_str(), m_fileRoot.c_str(), timestamp); ::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);
#else #else
::sprintf(filename, "%s/%s%s.log", m_filePath.c_str(), m_fileRoot.c_str(), timestamp); ::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);
#endif #endif
if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) { if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) {
@ -94,13 +86,12 @@ static bool LogOpen()
return status; return status;
} }
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int timestampLogs) bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel)
{ {
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_timestampLogs = timestampLogs;
m_daemon = daemon; m_daemon = daemon;
if (m_daemon) if (m_daemon)

2
Log.h
View file

@ -30,7 +30,7 @@
extern void Log(unsigned int level, const char* fmt, ...); extern void Log(unsigned int level, const char* fmt, ...);
extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel, unsigned int timestampLogs); extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel);
extern void LogFinalise(); extern void LogFinalise();
#endif #endif

View file

@ -26,7 +26,6 @@ DisplayLevel=1
FileLevel=1 FileLevel=1
FilePath=. FilePath=.
FileRoot=MMDVM FileRoot=MMDVM
TimestampLogs=1
[CW Id] [CW Id]
Enable=1 Enable=1

View file

@ -242,9 +242,9 @@ int CMMDVMHost::run()
#endif #endif
#if !defined(_WIN32) && !defined(_WIN64) #if !defined(_WIN32) && !defined(_WIN64)
ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogTimestampLogs()); ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
#else #else
ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogTimestampLogs()); ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
#endif #endif
if (!ret) { if (!ret) {
::fprintf(stderr, "MMDVMHost: unable to open the log file\n"); ::fprintf(stderr, "MMDVMHost: unable to open the log file\n");

View file

@ -51,7 +51,7 @@ int main(int argc, char** argv)
CRemoteCommand::CRemoteCommand(unsigned int port) : CRemoteCommand::CRemoteCommand(unsigned int port) :
m_port(port) m_port(port)
{ {
::LogInitialise(false, ".", "RemoteCommand", 2U, 2U, 1U); ::LogInitialise(false, ".", "RemoteCommand", 2U, 2U);
} }
CRemoteCommand::~CRemoteCommand() CRemoteCommand::~CRemoteCommand()