From d45f3ab49ba2ee44107f80fb651ac804b1292f9e Mon Sep 17 00:00:00 2001 From: Geoffrey Merck F4FXL - KC3FRA Date: Sat, 3 Nov 2018 06:49:11 +0100 Subject: [PATCH] Revert to log files with dates This also restores the original log files behavior --- Common/Logger.cpp | 27 +++++++++++---------------- Common/Logger.h | 9 +++------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Common/Logger.cpp b/Common/Logger.cpp index 8edd3b1..4de2e2e 100644 --- a/Common/Logger.cpp +++ b/Common/Logger.cpp @@ -19,20 +19,17 @@ #include "Logger.h" CLogger::CLogger(const wxString& directory, const wxString& name) : -#if(defined(__WINDOWS__)) -m_day(0), -#endif wxLog(), m_name(name), m_file(NULL), -m_fileName() +m_fileName(), +m_day(0) { m_file = new wxFFile; m_fileName.SetPath(directory); m_fileName.SetExt(wxT("log")); -#if(defined(__WINDOWS__)) time_t timestamp; ::time(×tamp); struct tm* tm = ::gmtime(×tamp); @@ -42,9 +39,6 @@ m_fileName() m_day = tm->tm_yday; m_fileName.SetName(text); -#else - m_fileName.SetName(m_name); -#endif bool ret = m_file->Open(m_fileName.GetFullPath(), wxT("a+t")); if (!ret) { @@ -61,10 +55,11 @@ CLogger::~CLogger() delete m_file; } -void CLogger::DoLogRecord(wxLogLevel level, const wxString& msg, const wxLogRecordInfo& info) +void CLogger::DoLog(wxLogLevel level, const wxChar* msg, time_t timestamp) { wxASSERT(m_file != NULL); wxASSERT(m_file->IsOpened()); + wxASSERT(msg != NULL); wxString letter; @@ -80,23 +75,23 @@ void CLogger::DoLogRecord(wxLogLevel level, const wxString& msg, const wxLogReco default: letter = wxT("U"); break; } - struct tm* tm = ::gmtime(&info.timestamp); + struct tm* tm = ::gmtime(×tamp); wxString message; - message.Printf(wxT("%s: %04d-%02d-%02d %02d:%02d:%02d: %s\n"), letter.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, msg.c_str()); + message.Printf(wxT("%s: %04d-%02d-%02d %02d:%02d:%02d: %s\n"), letter.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, msg); - logString(message, info.timestamp); + DoLogString(message.c_str(), timestamp); if (level == wxLOG_FatalError) ::abort(); } -void CLogger::logString(const wxString& msg, time_t timestamp) +void CLogger::DoLogString(const wxChar* msg, time_t timestamp) { wxASSERT(m_file != NULL); wxASSERT(m_file->IsOpened()); + wxASSERT(msg != NULL); -#if(defined(__WINDOWS__)) struct tm* tm = ::gmtime(×tamp); int day = tm->tm_yday; @@ -115,8 +110,8 @@ void CLogger::logString(const wxString& msg, time_t timestamp) return; } } -#endif - m_file->Write(msg); + m_file->Write(wxString(msg)); m_file->Flush(); } + diff --git a/Common/Logger.h b/Common/Logger.h index 0d082f0..ccdae79 100644 --- a/Common/Logger.h +++ b/Common/Logger.h @@ -22,24 +22,21 @@ #include #include #include -#include class CLogger : public wxLog { public: CLogger(const wxString& directory, const wxString& name); virtual ~CLogger(); - virtual void DoLogRecord(wxLogLevel level, const wxString& msg, const wxLogRecordInfo& info); + virtual void DoLog(wxLogLevel level, const wxChar* msg, time_t timestamp); + virtual void DoLogString(const wxChar* msg, time_t timestamp); private: wxString m_name; wxFFile* m_file; wxFileName m_fileName; -#if(defined(__WINDOWS__)) int m_day; -#endif - - void logString(const wxString& msg, time_t timestamp); }; #endif +