From 878ff1812359f51bdb1ea7194e4780dd8f7fd5af Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 27 Dec 2021 19:28:59 +0100 Subject: [PATCH] Add primitive logging --- APRSWriter.cpp | 5 +- APRSWriterThread.cpp | 37 ++++----- AnnouncementUnit.cpp | 3 +- AudioUnit.cpp | 27 +++---- ConnectData.cpp | 3 +- DCSHandler.cpp | 38 ++++----- DCSProtocolHandlerPool.cpp | 13 ++-- DDHandler.cpp | 28 +++---- DExtraHandler.cpp | 38 ++++----- DExtraProtocolHandlerPool.cpp | 13 ++-- DPlusAuthenticator.cpp | 17 ++-- DPlusHandler.cpp | 38 ++++----- DPlusProtocolHandlerPool.cpp | 13 ++-- DStarGatewayApp.cpp | 19 ++--- DStarGatewayConfig.cpp | 25 +++--- DStarGatewayThread.cpp | 76 +++++++++--------- DummyRepeaterProtocolHandler.cpp | 4 +- EchoUnit.cpp | 5 +- G2Handler.cpp | 8 +- G2ProtocolHandler.cpp | 6 +- HBRepeaterProtocolHandler.cpp | 10 +-- HeaderLogger.cpp | 2 +- HostFile.cpp | 2 +- IRCClient.cpp | 41 +++++----- IRCDDBApp.cpp | 25 +++--- IRCDDBClient.cpp | 77 +++++++++--------- IRCDDBMultiClient.cpp | 11 ++- IRCProtocol.cpp | 4 +- IRCReceiver.cpp | 9 ++- IcomRepeaterProtocolHandler.cpp | 50 ++++++------ Log.cpp | 42 ++++++++++ Log.h | 110 ++++++++++++++++++++++++-- RemoteHandler.cpp | 18 ++--- RepeaterHandler.cpp | 120 ++++++++++++++--------------- RepeaterProtocolHandlerFactory.cpp | 6 +- TCPReaderWriterClient.cpp | 18 ++--- UDPReaderWriter.cpp | 17 ++-- Utils.cpp | 15 ++-- VersionUnit.cpp | 3 +- 39 files changed, 579 insertions(+), 417 deletions(-) create mode 100644 Log.cpp diff --git a/APRSWriter.cpp b/APRSWriter.cpp index 5cffc44..82e1ff4 100644 --- a/APRSWriter.cpp +++ b/APRSWriter.cpp @@ -26,6 +26,7 @@ #include "APRSWriter.h" #include "DStarDefines.h" #include "Defs.h" +#include "Log.h" CAPRSEntry::CAPRSEntry(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl) : m_callsign(callsign), @@ -204,7 +205,7 @@ void CAPRSWriter::writeHeader(const std::string& callsign, const CHeaderData& he { CAPRSEntry* entry = m_array[callsign]; if (entry == NULL) { - wxLogError("Cannot find the callsign \"%s\" in the APRS array", callsign.c_str()); + CLog::logError("Cannot find the callsign \"%s\" in the APRS array", callsign.c_str()); return; } @@ -222,7 +223,7 @@ void CAPRSWriter::writeData(const std::string& callsign, const CAMBEData& data) CAPRSEntry* entry = m_array[callsign]; if (entry == NULL) { - wxLogError("Cannot find the callsign \"%s\" in the APRS array", callsign.c_str()); + CLog::logError("Cannot find the callsign \"%s\" in the APRS array", callsign.c_str()); return; } diff --git a/APRSWriterThread.cpp b/APRSWriterThread.cpp index d8d70d5..2dd30e0 100644 --- a/APRSWriterThread.cpp +++ b/APRSWriterThread.cpp @@ -25,6 +25,7 @@ #include "DStarDefines.h" #include "Utils.h" #include "Defs.h" +#include "Log.h" // #define DUMP_TX @@ -100,11 +101,11 @@ bool CAPRSWriterThread::start() void* CAPRSWriterThread::Entry() { - printf("Starting the APRS Writer thread"); + CLog::logInfo("Starting the APRS Writer thread"); m_connected = connect(); if (!m_connected) { - printf("Connect attempt to the APRS server has failed"); + CLog::logInfo("Connect attempt to the APRS server has failed"); startReconnectionTimer(); } @@ -116,7 +117,7 @@ void* CAPRSWriterThread::Entry() m_connected = connect(); if (!m_connected) { - printf("Reconnect attempt to the APRS server has failed"); + CLog::logInfo("Reconnect attempt to the APRS server has failed"); startReconnectionTimer(); } } @@ -129,7 +130,7 @@ void* CAPRSWriterThread::Entry() char* p = m_queue.getData(); std::string text(p); - printf("APRS ==> %s", text.c_str()); + CLog::logInfo("APRS ==> %s", text.c_str()); ::strcat(p, "\r\n"); @@ -137,7 +138,7 @@ void* CAPRSWriterThread::Entry() if (!ret) { m_connected = false; m_socket.close(); - printf("Connection to the APRS thread has failed"); + CLog::logInfo("Connection to the APRS thread has failed"); startReconnectionTimer(); } @@ -148,19 +149,19 @@ void* CAPRSWriterThread::Entry() int length = m_socket.readLine(line, APRS_TIMEOUT); /*if (length == 0) - wxLogWarning(wxT("No response from the APRS server after %u seconds"), APRS_TIMEOUT);*/ + CLog::logWarning((wxT("No response from the APRS server after %u seconds"), APRS_TIMEOUT);*/ if (length < 0) { m_connected = false; m_socket.close(); - printf("Error when reading from the APRS server"); + CLog::logInfo("Error when reading from the APRS server"); startReconnectionTimer(); } if(length > 0 && line[0] != '#'//check if we have something and if that something is an APRS frame && m_APRSReadCallback != NULL)//do we have someone wanting an APRS Frame? { - //printf("Received APRS Frame : ") + line); + //CLog::logInfo("Received APRS Frame : ") + line); m_APRSReadCallback(std::string(line)); } } @@ -178,13 +179,13 @@ void* CAPRSWriterThread::Entry() } catch (std::exception& e) { std::string message(e.what()); - printf("Exception raised in the APRS Writer thread - \"%s\"", message.c_str()); + CLog::logInfo("Exception raised in the APRS Writer thread - \"%s\"", message.c_str()); } catch (...) { - printf("Unknown exception raised in the APRS Writer thread"); + CLog::logInfo("Unknown exception raised in the APRS Writer thread"); } - printf("Stopping the APRS Writer thread"); + CLog::logInfo("Stopping the APRS Writer thread"); return NULL; } @@ -237,11 +238,11 @@ bool CAPRSWriterThread::connect() std::string serverResponse(""); length = m_socket.readLine(serverResponse, APRS_TIMEOUT); if (length == 0) { - printf("No reply from the APRS server after %u seconds", APRS_TIMEOUT); + CLog::logInfo("No reply from the APRS server after %u seconds", APRS_TIMEOUT); m_socket.close(); return false; } - printf("Received login banner : %s", serverResponse.c_str()); + CLog::logInfo("Received login banner : %s", serverResponse.c_str()); std::string filter(m_filter); if (filter.length() > 0) filter = " filter " + filter; @@ -250,7 +251,7 @@ bool CAPRSWriterThread::connect() << " pass " << m_password << " vers " << (m_clientName.length() ? m_clientName : "ircDDBGateway") << filter; - //printf("Connect String : ") + connectString); + //CLog::logInfo("Connect String : ") + connectString); ret = m_socket.writeLine(connectString.str()); if (!ret) { m_socket.close(); @@ -259,19 +260,19 @@ bool CAPRSWriterThread::connect() length = m_socket.readLine(serverResponse, APRS_TIMEOUT); if (length == 0) { - printf("No reply from the APRS server after %u seconds", APRS_TIMEOUT); + CLog::logInfo("No reply from the APRS server after %u seconds", APRS_TIMEOUT); m_socket.close(); return false; } if (length < 0) { - printf("Error when reading from the APRS server"); + CLog::logInfo("Error when reading from the APRS server"); m_socket.close(); return false; } - printf("Response from APRS server: %s", serverResponse.c_str()); + CLog::logInfo("Response from APRS server: %s", serverResponse.c_str()); - printf("Connected to the APRS server"); + CLog::logInfo("Connected to the APRS server"); return true; } diff --git a/AnnouncementUnit.cpp b/AnnouncementUnit.cpp index 43ff4c0..914bd23 100644 --- a/AnnouncementUnit.cpp +++ b/AnnouncementUnit.cpp @@ -25,6 +25,7 @@ #include "HeaderData.h" #include "AnnouncementUnit.h" #include "Utils.h" +#include "Log.h" CAnnouncementUnit::CAnnouncementUnit(IRepeaterCallback* handler, const std::string& callsign, const std::string& fileName, const std::string& name) : m_handler(handler), @@ -41,7 +42,7 @@ m_id(0U) m_name.resize(SHORT_CALLSIGN_LENGTH, ' '); - printf("Connected '%s' to %s using file - %s\n", name.c_str(), callsign.c_str(), fileName.c_str()); + CLog::logInfo("Connected '%s' to %s using file - %s\n", name.c_str(), callsign.c_str(), fileName.c_str()); } CAnnouncementUnit::~CAnnouncementUnit() diff --git a/AudioUnit.cpp b/AudioUnit.cpp index 64d1bbc..0c68261 100644 --- a/AudioUnit.cpp +++ b/AudioUnit.cpp @@ -28,6 +28,7 @@ #include "HeaderData.h" #include "AudioUnit.h" #include "Utils.h" +#include "Log.h" unsigned char* CAudioUnit::m_ambe = NULL; unsigned int CAudioUnit::m_ambeLength = 0U; @@ -247,7 +248,7 @@ bool CAudioUnit::lookup(unsigned int id, const std::string &name) { CIndexRecord* info = m_index[name]; if (info == NULL) { - // wxLogError(wxT("Cannot find the AMBE index for *%s*"), name.c_str()); + // CLog::logError(wxT("Cannot find the AMBE index for *%s*"), name.c_str()); return false; } @@ -335,12 +336,12 @@ bool CAudioUnit::readAMBE(const std::string& name) struct stat sbuf; if (stat(fileName.c_str(), &sbuf)) { - printf("File %s not readable\n", fileName.c_str()); + CLog::logInfo("File %s not readable\n", fileName.c_str()); fileName.assign(CFG_DIR); fileName.append("/data/"); fileName += name; if (stat(fileName.c_str(), &sbuf)) { - printf("File %s not readable\n", fileName.c_str()); + CLog::logInfo("File %s not readable\n", fileName.c_str()); return false; } } @@ -348,23 +349,23 @@ bool CAudioUnit::readAMBE(const std::string& name) FILE *file = fopen(fileName.c_str(), "rb"); if (NULL == file) { - printf("Cannot open %s for reading\n", fileName.c_str()); + CLog::logInfo("Cannot open %s for reading\n", fileName.c_str()); return false; } - printf("Reading %s\n", fileName.c_str()); + CLog::logInfo("Reading %s\n", fileName.c_str()); unsigned char buffer[VOICE_FRAME_LENGTH_BYTES]; size_t n = fread(buffer, 4, 1, file); if (n != 4) { - printf("Unable to read the header from %s\n", fileName.c_str()); + CLog::logInfo("Unable to read the header from %s\n", fileName.c_str()); fclose(file); return false; } if (memcmp(buffer, "AMBE", 4)) { - printf("Invalid header from %s\n", fileName.c_str()); + CLog::logInfo("Invalid header from %s\n", fileName.c_str()); fclose(file); return false; } @@ -383,7 +384,7 @@ bool CAudioUnit::readAMBE(const std::string& name) n = fread(p, length, 1, file); if (n != length) { - printf("Unable to read the AMBE data from %s\n", fileName.c_str()); + CLog::logInfo("Unable to read the AMBE data from %s\n", fileName.c_str()); fclose(file); delete[] m_ambe; m_ambe = NULL; @@ -402,26 +403,26 @@ bool CAudioUnit::readIndex(const std::string& name) struct stat sbuf; if (stat(fileName.c_str(), &sbuf)) { - printf("File %s not readable\n", fileName.c_str()); + CLog::logInfo("File %s not readable\n", fileName.c_str()); fileName.assign(CFG_DIR); fileName.append("/data/"); fileName += name; if (stat(fileName.c_str(), &sbuf)) { - printf("File %s not readable\n", fileName.c_str()); + CLog::logInfo("File %s not readable\n", fileName.c_str()); return false; } } FILE *file = fopen(fileName.c_str(), "r"); if (NULL == file) { - printf("Cannot open %s for reading\n", fileName.c_str()); + CLog::logInfo("Cannot open %s for reading\n", fileName.c_str()); return false; } // Add a silence entry at the beginning m_index[" "] = new CIndexRecord(" ", 0, SILENCE_LENGTH); - printf("Reading %s\n", fileName.c_str()); + CLog::logInfo("Reading %s\n", fileName.c_str()); char line[128]; while (fgets(line, 128, file)) { @@ -437,7 +438,7 @@ bool CAudioUnit::readIndex(const std::string& name) unsigned long length = std::stoul(leng); if (start >= m_ambeLength || (start + length) >= m_ambeLength) - printf("The start or end for *%s* is out of range, start: %lu, end: %lu\n", name.c_str(), start, start + length); + CLog::logInfo("The start or end for *%s* is out of range, start: %lu, end: %lu\n", name.c_str(), start, start + length); else m_index[name] = new CIndexRecord(name, start + SILENCE_LENGTH, length); } diff --git a/ConnectData.cpp b/ConnectData.cpp index a143987..4cf8701 100644 --- a/ConnectData.cpp +++ b/ConnectData.cpp @@ -27,6 +27,7 @@ #include "DStarDefines.h" #include "Version.h" #include "Utils.h" +#include "Log.h" const char *HTML = "
%s DStarGateway %s
"; @@ -256,7 +257,7 @@ bool CConnectData::setDPlusData(const unsigned char* data, unsigned int length, case 8U: { std::string reply((const char*)(data + 4U), 4U); - printf("D-Plus reply is %.4s\n", reply.c_str()); + CLog::logInfo("D-Plus reply is %.4s\n", reply.c_str()); if (::memcmp(data + 4U, "OKRW", 4U) == 0) m_type = CT_ACK; diff --git a/DCSHandler.cpp b/DCSHandler.cpp index 6e0f97c..b81f442 100644 --- a/DCSHandler.cpp +++ b/DCSHandler.cpp @@ -240,7 +240,7 @@ void CDCSHandler::process(CPollData& poll) } } - wxLogMessage("Unknown incoming DCS poll from %s", reflector.c_str()); + CLog::logInfo("Unknown incoming DCS poll from %s", reflector.c_str()); } void CDCSHandler::process(CConnectData& connect) @@ -285,14 +285,14 @@ void CDCSHandler::process(CConnectData& connect) // Check the validity of our repeater callsign IReflectorCallback* handler = CRepeaterHandler::findDVRepeater(reflectorCallsign); if (handler == NULL) { - wxLogMessage("DCS connect to unknown reflector %s from %s", reflectorCallsign.c_str(), repeaterCallsign.c_str()); + CLog::logInfo("DCS connect to unknown reflector %s from %s", reflectorCallsign.c_str(), repeaterCallsign.c_str()); CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, connect.getYourAddress(), connect.getYourPort()); m_incoming->writeConnect(reply); return; } // A new connect packet indicates the need for a new entry - wxLogMessage("New incoming DCS link to %s from %s", reflectorCallsign.c_str(), repeaterCallsign.c_str()); + CLog::logInfo("New incoming DCS link to %s from %s", reflectorCallsign.c_str(), repeaterCallsign.c_str()); CDCSHandler* dcs = new CDCSHandler(handler, repeaterCallsign, reflectorCallsign, m_incoming, yourAddress, yourPort, DIR_INCOMING); @@ -312,7 +312,7 @@ void CDCSHandler::process(CConnectData& connect) CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, yourAddress, yourPort); m_incoming->writeConnect(reply); - wxLogError("No space to add new DCS link, ignoring"); + CLog::logError("No space to add new DCS link, ignoring"); delete dcs; } } @@ -346,7 +346,7 @@ void CDCSHandler::link(IReflectorCallback* handler, const std::string& repeater, CConnectData reply(m_gatewayType, repeater, gateway, CT_LINK1, address, DCS_PORT); protoHandler->writeConnect(reply); } else { - wxLogError("No space to add new DCS link, ignoring"); + CLog::logError("No space to add new DCS link, ignoring"); delete dcs; } } @@ -361,7 +361,7 @@ void CDCSHandler::unlink(IReflectorCallback* handler, const std::string& callsig if (exclude) { if (reflector->m_direction == DIR_OUTGOING && reflector->m_destination == handler && reflector->m_reflector != callsign) { - wxLogMessage("Removing outgoing DCS link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); + CLog::logInfo("Removing outgoing DCS link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); if (reflector->m_linkState == DCS_LINKING || reflector->m_linkState == DCS_LINKED) { CConnectData connect(reflector->m_repeater, reflector->m_reflector, CT_UNLINK, reflector->m_yourAddress, reflector->m_yourPort); @@ -376,7 +376,7 @@ void CDCSHandler::unlink(IReflectorCallback* handler, const std::string& callsig } } else { if (reflector->m_destination == handler && reflector->m_reflector == callsign) { - wxLogMessage("Removing DCS link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); + CLog::logInfo("Removing DCS link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); if (reflector->m_linkState == DCS_LINKING || reflector->m_linkState == DCS_LINKED) { CConnectData connect(reflector->m_repeater, reflector->m_reflector, CT_UNLINK, reflector->m_yourAddress, reflector->m_yourPort); @@ -420,7 +420,7 @@ void CDCSHandler::unlink() if (reflector != NULL) { if (!reflector->m_repeater.empty()) { - wxLogMessage("Unlinking from DCS reflector %s", reflector->m_reflector.c_str()); + CLog::logInfo("Unlinking from DCS reflector %s", reflector->m_reflector.c_str()); CConnectData connect(reflector->m_repeater, reflector->m_reflector, CT_UNLINK, reflector->m_yourAddress, reflector->m_yourPort); reflector->m_handler->writeConnect(connect); @@ -460,10 +460,10 @@ void CDCSHandler::gatewayUpdate(const std::string& reflector, const std::string& if (reflector->m_reflector.substr(0, LONG_CALLSIGN_LENGTH - 1U) == gateway) { if (!address.empty()) { // A new address, change the value - wxLogMessage("Changing IP address of DCS gateway or reflector %s to %s", reflector->m_reflector.c_str(), address.c_str()); + CLog::logInfo("Changing IP address of DCS gateway or reflector %s to %s", reflector->m_reflector.c_str(), address.c_str()); reflector->m_yourAddress.s_addr = ::inet_addr(address.c_str()); } else { - wxLogMessage("IP address for DCS gateway or reflector %s has been removed", reflector->m_reflector.c_str()); + CLog::logInfo("IP address for DCS gateway or reflector %s has been removed", reflector->m_reflector.c_str()); // No address, this probably shouldn't happen.... if (reflector->m_direction == DIR_OUTGOING && reflector->m_destination != NULL) @@ -515,7 +515,7 @@ void CDCSHandler::processInt(CAMBEData& data) if (m_whiteList != NULL) { bool res = m_whiteList->isInList(my); if (!res) { - wxLogMessage("%s rejected from DCS as not found in the white list", my.c_str()); + CLog::logInfo("%s rejected from DCS as not found in the white list", my.c_str()); m_dcsId = 0x00U; return; } @@ -524,7 +524,7 @@ void CDCSHandler::processInt(CAMBEData& data) if (m_blackList != NULL) { bool res = m_blackList->isInList(my); if (res) { - wxLogMessage("%s rejected from DCS as found in the black list", my.c_str()); + CLog::logInfo("%s rejected from DCS as found in the black list", my.c_str()); m_dcsId = 0x00U; return; } @@ -644,7 +644,7 @@ bool CDCSHandler::processInt(CConnectData& connect, CD_TYPE type) return false; if (m_linkState == DCS_LINKING) { - wxLogMessage("DCS ACK message received from %s", GET_DISP_REFLECTOR(this).c_str()); + CLog::logInfo("DCS ACK message received from %s", GET_DISP_REFLECTOR(this).c_str()); if (m_direction == DIR_OUTGOING && m_destination != NULL) m_destination->linkUp(DP_DCS, GET_DISP_REFLECTOR(this)); @@ -661,7 +661,7 @@ bool CDCSHandler::processInt(CConnectData& connect, CD_TYPE type) return false; if (m_linkState == DCS_LINKING) { - wxLogMessage("DCS NAK message received from %s", GET_DISP_REFLECTOR(this).c_str()); + CLog::logInfo("DCS NAK message received from %s", GET_DISP_REFLECTOR(this).c_str()); if (m_direction == DIR_OUTGOING && m_destination != NULL) m_destination->linkRefused(DP_DCS, GET_DISP_REFLECTOR(this)); @@ -670,7 +670,7 @@ bool CDCSHandler::processInt(CConnectData& connect, CD_TYPE type) } if (m_linkState == DCS_UNLINKING) { - wxLogMessage("DCS NAK message received from %s", GET_DISP_REFLECTOR(this).c_str()); + CLog::logInfo("DCS NAK message received from %s", GET_DISP_REFLECTOR(this).c_str()); if (m_direction == DIR_OUTGOING && m_destination != NULL) m_destination->linkFailed(DP_DCS, m_reflector, false); @@ -685,7 +685,7 @@ bool CDCSHandler::processInt(CConnectData& connect, CD_TYPE type) return false; if (m_linkState == DCS_LINKED) { - wxLogMessage("DCS disconnect message received from %s", GET_DISP_REFLECTOR(this).c_str()); + CLog::logInfo("DCS disconnect message received from %s", GET_DISP_REFLECTOR(this).c_str()); if (m_direction == DIR_OUTGOING && m_destination != NULL) m_destination->linkFailed(DP_DCS, GET_DISP_REFLECTOR(this), false); @@ -716,13 +716,13 @@ bool CDCSHandler::clockInt(unsigned int ms) switch (m_linkState) { case DCS_LINKING: - wxLogMessage("DCS link to %s has failed to connect", GET_DISP_REFLECTOR(this).c_str()); + CLog::logInfo("DCS link to %s has failed to connect", GET_DISP_REFLECTOR(this).c_str()); break; case DCS_LINKED: - wxLogMessage("DCS link to %s has failed (poll inactivity)", GET_DISP_REFLECTOR(this).c_str()); + CLog::logInfo("DCS link to %s has failed (poll inactivity)", GET_DISP_REFLECTOR(this).c_str()); break; case DCS_UNLINKING: - wxLogMessage("DCS link to %s has failed to disconnect cleanly", GET_DISP_REFLECTOR(this).c_str()); + CLog::logInfo("DCS link to %s has failed to disconnect cleanly", GET_DISP_REFLECTOR(this).c_str()); break; default: break; diff --git a/DCSProtocolHandlerPool.cpp b/DCSProtocolHandlerPool.cpp index 354c921..d3ab973 100644 --- a/DCSProtocolHandlerPool.cpp +++ b/DCSProtocolHandlerPool.cpp @@ -22,6 +22,7 @@ #include "DCSProtocolHandlerPool.h" #include "Utils.h" +#include "Log.h" CDCSProtocolHandlerPool::CDCSProtocolHandlerPool(const unsigned int port, const std::string &addr) : m_basePort(port), @@ -29,7 +30,7 @@ m_address(addr) { assert(port > 0U); m_index = m_pool.end(); - printf("DCS UDP port base = %u\n", port); + CLog::logInfo("DCS UDP port base = %u\n", port); } CDCSProtocolHandlerPool::~CDCSProtocolHandlerPool() @@ -59,14 +60,14 @@ CDCSProtocolHandler *CDCSProtocolHandlerPool::getHandler(unsigned int port) if (proto) { if (proto->open()) { m_pool[port] = proto; - printf("New CDCSProtocolHandler now on port %u.\n", port); + CLog::logInfo("New CDCSProtocolHandler now on port %u.\n", port); } else { delete proto; proto = NULL; - printf("ERROR: Can't open new DCS UDP port %u!\n", port); + CLog::logInfo("ERROR: Can't open new DCS UDP port %u!\n", port); } } else - printf("ERROR: Can't allocate new CDCSProtocolHandler at port %u\n", port); + CLog::logInfo("ERROR: Can't allocate new CDCSProtocolHandler at port %u\n", port); return proto; } @@ -77,13 +78,13 @@ void CDCSProtocolHandlerPool::release(CDCSProtocolHandler *handler) if (it->second == handler) { it->second->close(); delete it->second; - printf("Releasing CDCSProtocolHandler on port %u.\n", it->first); + CLog::logInfo("Releasing CDCSProtocolHandler on port %u.\n", it->first); m_pool.erase(it); return; } } // we should never get here! - printf("ERROR: could not find CDCSProtocolHander (port=%u) to release!\n", handler->getPort()); + CLog::logInfo("ERROR: could not find CDCSProtocolHander (port=%u) to release!\n", handler->getPort()); } DCS_TYPE CDCSProtocolHandlerPool::read() diff --git a/DDHandler.cpp b/DDHandler.cpp index b3144fb..047a1da 100644 --- a/DDHandler.cpp +++ b/DDHandler.cpp @@ -110,7 +110,7 @@ void CDDHandler::initialise(unsigned int maxRoutes, const std::string& name) #if defined(__linux__) m_fd = ::open("/dev/net/tun", O_RDWR); if (m_fd < 0) { - wxLogError("Cannot open /dev/net/tun"); + CLog::logError("Cannot open /dev/net/tun"); return; } @@ -121,18 +121,18 @@ void CDDHandler::initialise(unsigned int maxRoutes, const std::string& name) ::strcpy(ifr1.ifr_name, "tap%d"); if (::ioctl(m_fd, TUNSETIFF, (void *)&ifr1) < 0) { - wxLogError("TUNSETIFF ioctl failed, closing the tap device"); + CLog::logError("TUNSETIFF ioctl failed, closing the tap device"); ::close(m_fd); m_fd = -1; return; } std::string device = std::string(ifr1.ifr_name); - wxLogMessage("DD mode Tap interface created on %s", device.c_str()); + CLog::logInfo("DD mode Tap interface created on %s", device.c_str()); int fd = ::socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) { - wxLogError("Unable to open the config socket, closing the tap device"); + CLog::logError("Unable to open the config socket, closing the tap device"); ::close(m_fd); m_fd = -1; return; @@ -144,7 +144,7 @@ void CDDHandler::initialise(unsigned int maxRoutes, const std::string& name) ifr2.ifr_flags = IFF_UP | IFF_BROADCAST | IFF_MULTICAST; if (::ioctl(fd, SIOCSIFFLAGS, (void *)&ifr2) < 0) { - wxLogError("SIOCSIFFLAGS ioctl failed, closing the tap device"); + CLog::logError("SIOCSIFFLAGS ioctl failed, closing the tap device"); ::close(m_fd); m_fd = -1; return; @@ -219,7 +219,7 @@ void CDDHandler::process(CDDData& data) } if (!found) { - wxLogMessage("Adding DD user %s with ethernet address %02X:%02X:%02X:%02X:%02X:%02X", myCall1.c_str(), + CLog::logInfo("Adding DD user %s with ethernet address %02X:%02X:%02X:%02X:%02X:%02X", myCall1.c_str(), address[0], address[1], address[2], address[3], address[4], address[5]); CEthernet* ethernet = new CEthernet(address, myCall1); @@ -236,7 +236,7 @@ void CDDHandler::process(CDDData& data) } if (!found) { - wxLogError("No space to add new DD ethernet address"); + CLog::logError("No space to add new DD ethernet address"); delete ethernet; return; } @@ -247,7 +247,7 @@ void CDDHandler::process(CDDData& data) ssize_t len = ::write(m_fd, (char*)m_buffer, length); if (len != ssize_t(length)) - wxLogError("Error returned from write()"); + CLog::logError("Error returned from write()"); #endif } @@ -276,7 +276,7 @@ CDDData* CDDHandler::read() int ret = ::select(m_fd + 1, &readFds, NULL, NULL, &tv); if (ret < 0) { - wxLogError("Error returned from select()"); + CLog::logError("Error returned from select()"); return NULL; } @@ -293,7 +293,7 @@ CDDData* CDDHandler::read() ssize_t len = ::read(m_fd, (char*)m_buffer, BUFFER_LENGTH); if (len <= 0) { - wxLogError("Error returned from read()"); + CLog::logError("Error returned from read()"); return NULL; } @@ -318,17 +318,17 @@ CDDData* CDDHandler::read() } if (ethernet == NULL) { - wxLogWarning("Cannot find the ethernet address of %02X:%02X:%02X:%02X:%02X:%02X in the ethernet list", address[0], address[1], address[2], address[3], address[4], address[5]); + CLog::logWarning("Cannot find the ethernet address of %02X:%02X:%02X:%02X:%02X:%02X in the ethernet list", address[0], address[1], address[2], address[3], address[4], address[5]); return NULL; } CRepeaterHandler* handler = CRepeaterHandler::findDDRepeater(); if (handler == NULL) { - wxLogWarning("Incoming DD data to unknown repeater"); + CLog::logWarning("Incoming DD data to unknown repeater"); return NULL; } - // wxLogMessage("Mapping ethernet address %02X:%02X:%02X:%02X:%02X:%02X to user %s", + // CLog::logInfo("Mapping ethernet address %02X:%02X:%02X:%02X:%02X:%02X to user %s", // address[0], address[1], address[2], address[3], address[4], address[5], // ethernet->getCallsign().c_str()); @@ -377,7 +377,7 @@ void CDDHandler::writeStatus(const CEthernet& ethernet) std::ofstream file; file.open(fullName, std::ios::app); if (!file.is_open()) { - wxLogError("Unable to open %s for writing", fullName.c_str()); + CLog::logError("Unable to open %s for writing", fullName.c_str()); return; } diff --git a/DExtraHandler.cpp b/DExtraHandler.cpp index 3016da6..b9bbacf 100644 --- a/DExtraHandler.cpp +++ b/DExtraHandler.cpp @@ -298,7 +298,7 @@ void CDExtraHandler::process(const CPollData& poll) return; // An unmatched poll indicates the need for a new entry - wxLogMessage("New incoming DExtra Dongle from %s", reflector.c_str()); + CLog::logInfo("New incoming DExtra Dongle from %s", reflector.c_str()); CDExtraHandler* handler = new CDExtraHandler(m_incoming, reflector, yourAddress, yourPort, DIR_INCOMING); @@ -317,7 +317,7 @@ void CDExtraHandler::process(const CPollData& poll) CPollData poll(m_callsign, yourAddress, yourPort); m_incoming->writePoll(poll); } else { - wxLogError("No space to add new DExtra Dongle, ignoring"); + CLog::logError("No space to add new DExtra Dongle, ignoring"); delete handler; } } @@ -366,14 +366,14 @@ void CDExtraHandler::process(CConnectData& connect) // Check the validity of our repeater callsign IReflectorCallback* handler = CRepeaterHandler::findDVRepeater(reflectorCallsign); if (handler == NULL) { - wxLogMessage("DExtra connect to unknown reflector %s from %s", reflectorCallsign.c_str(), repeaterCallsign.c_str()); + CLog::logInfo("DExtra connect to unknown reflector %s from %s", reflectorCallsign.c_str(), repeaterCallsign.c_str()); CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, yourAddress, yourPort); m_incoming->writeConnect(reply); return; } // A new connect packet indicates the need for a new entry - wxLogMessage("New incoming DExtra link to %s from %s", reflectorCallsign.c_str(), repeaterCallsign.c_str()); + CLog::logInfo("New incoming DExtra link to %s from %s", reflectorCallsign.c_str(), repeaterCallsign.c_str()); CDExtraHandler* dextra = new CDExtraHandler(handler, repeaterCallsign, reflectorCallsign, m_incoming, yourAddress, yourPort, DIR_INCOMING); @@ -398,7 +398,7 @@ void CDExtraHandler::process(CConnectData& connect) CConnectData reply(repeaterCallsign, reflectorCallsign, CT_NAK, yourAddress, yourPort); m_incoming->writeConnect(reply); - wxLogError("No space to add new DExtra repeater, ignoring"); + CLog::logError("No space to add new DExtra repeater, ignoring"); delete dextra; } } @@ -425,7 +425,7 @@ void CDExtraHandler::link(IReflectorCallback* handler, const std::string& repeat CConnectData reply(repeater, gateway, CT_LINK1, address, DEXTRA_PORT); protoHandler->writeConnect(reply); } else { - wxLogError("No space to add new DExtra link, ignoring"); + CLog::logError("No space to add new DExtra link, ignoring"); delete dextra; } } @@ -440,7 +440,7 @@ void CDExtraHandler::unlink(IReflectorCallback* handler, const std::string& call if (exclude) { if (reflector->m_direction == DIR_OUTGOING && reflector->m_destination == handler && reflector->m_reflector != callsign) { - wxLogMessage("Removing outgoing DExtra link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); + CLog::logInfo("Removing outgoing DExtra link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); if (reflector->m_linkState == DEXTRA_LINKING || reflector->m_linkState == DEXTRA_LINKED) { CConnectData connect(reflector->m_repeater, reflector->m_yourAddress, reflector->m_yourPort); @@ -455,7 +455,7 @@ void CDExtraHandler::unlink(IReflectorCallback* handler, const std::string& call } } else { if (reflector->m_destination == handler && reflector->m_reflector == callsign) { - wxLogMessage("Removing DExtra link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); + CLog::logInfo("Removing DExtra link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); if (reflector->m_linkState == DEXTRA_LINKING || reflector->m_linkState == DEXTRA_LINKED) { CConnectData connect(reflector->m_repeater, reflector->m_yourAddress, reflector->m_yourPort); @@ -502,7 +502,7 @@ void CDExtraHandler::unlink() if (reflector != NULL) { if (!reflector->m_repeater.empty()) { - wxLogMessage("Unlinking from DExtra reflector %s", reflector->m_reflector.c_str()); + CLog::logInfo("Unlinking from DExtra reflector %s", reflector->m_reflector.c_str()); CConnectData connect(reflector->m_repeater, reflector->m_yourAddress, reflector->m_yourPort); reflector->m_handler->writeConnect(connect); @@ -540,10 +540,10 @@ void CDExtraHandler::gatewayUpdate(const std::string& reflector, const std::stri if (reflector->m_reflector.substr(0, LONG_CALLSIGN_LENGTH - 1U) == gateway) { if (!address.empty()) { // A new address, change the value - wxLogMessage("Changing IP address of DExtra gateway or reflector %s to %s", reflector->m_reflector.c_str(), address.c_str()); + CLog::logInfo("Changing IP address of DExtra gateway or reflector %s to %s", reflector->m_reflector.c_str(), address.c_str()); reflector->m_yourAddress.s_addr = ::inet_addr(address.c_str()); } else { - wxLogMessage("IP address for DExtra gateway or reflector %s has been removed", reflector->m_reflector.c_str()); + CLog::logInfo("IP address for DExtra gateway or reflector %s has been removed", reflector->m_reflector.c_str()); // No address, this probably shouldn't happen.... if (reflector->m_direction == DIR_OUTGOING && reflector->m_destination != NULL) @@ -590,7 +590,7 @@ void CDExtraHandler::processInt(CHeaderData& header) if (m_whiteList != NULL) { bool res = m_whiteList->isInList(my); if (!res) { - wxLogMessage("%s rejected from DExtra as not found in the white list", my.c_str()); + CLog::logInfo("%s rejected from DExtra as not found in the white list", my.c_str()); m_dExtraId = 0x00U; return; } @@ -599,7 +599,7 @@ void CDExtraHandler::processInt(CHeaderData& header) if (m_blackList != NULL) { bool res = m_blackList->isInList(my); if (res) { - wxLogMessage("%s rejected from DExtra as found in the black list", my.c_str()); + CLog::logInfo("%s rejected from DExtra as found in the black list", my.c_str()); m_dExtraId = 0x00U; return; } @@ -743,7 +743,7 @@ bool CDExtraHandler::processInt(CConnectData& connect, CD_TYPE type) return false; if (m_linkState == DEXTRA_LINKING) { - wxLogMessage("DExtra ACK message received from %s", m_reflector.c_str()); + CLog::logInfo("DExtra ACK message received from %s", m_reflector.c_str()); if (m_direction == DIR_OUTGOING && m_destination != NULL) m_destination->linkUp(DP_DEXTRA, m_reflector); @@ -761,7 +761,7 @@ bool CDExtraHandler::processInt(CConnectData& connect, CD_TYPE type) return false; if (m_linkState == DEXTRA_LINKING) { - wxLogMessage("DExtra NAK message received from %s", m_reflector.c_str()); + CLog::logInfo("DExtra NAK message received from %s", m_reflector.c_str()); if (m_direction == DIR_OUTGOING && m_destination != NULL) m_destination->linkRefused(DP_DEXTRA, m_reflector); @@ -776,7 +776,7 @@ bool CDExtraHandler::processInt(CConnectData& connect, CD_TYPE type) return false; if (m_linkState == DEXTRA_LINKED) { - wxLogMessage("DExtra disconnect message received from %s", m_reflector.c_str()); + CLog::logInfo("DExtra disconnect message received from %s", m_reflector.c_str()); if (m_direction == DIR_OUTGOING && m_destination != NULL) m_destination->linkFailed(DP_DEXTRA, m_reflector, false); @@ -810,13 +810,13 @@ bool CDExtraHandler::clockInt(unsigned int ms) switch (m_linkState) { case DEXTRA_LINKING: - wxLogMessage("DExtra link to %s has failed to connect", m_reflector.c_str()); + CLog::logInfo("DExtra link to %s has failed to connect", m_reflector.c_str()); break; case DEXTRA_LINKED: - wxLogMessage("DExtra link to %s has failed (poll inactivity)", m_reflector.c_str()); + CLog::logInfo("DExtra link to %s has failed (poll inactivity)", m_reflector.c_str()); break; case DEXTRA_UNLINKING: - wxLogMessage("DExtra link to %s has failed to disconnect cleanly", m_reflector.c_str()); + CLog::logInfo("DExtra link to %s has failed to disconnect cleanly", m_reflector.c_str()); break; default: break; diff --git a/DExtraProtocolHandlerPool.cpp b/DExtraProtocolHandlerPool.cpp index 96301f3..d838961 100644 --- a/DExtraProtocolHandlerPool.cpp +++ b/DExtraProtocolHandlerPool.cpp @@ -21,6 +21,7 @@ #include "DExtraProtocolHandlerPool.h" #include "Utils.h" +#include "Log.h" CDExtraProtocolHandlerPool::CDExtraProtocolHandlerPool(const unsigned int port, const std::string &addr) : m_basePort(port), @@ -28,7 +29,7 @@ m_address(addr) { assert(port > 0U); m_index = m_pool.end(); - printf("DExtra UDP port base = %u\n", port); + CLog::logInfo("DExtra UDP port base = %u\n", port); } CDExtraProtocolHandlerPool::~CDExtraProtocolHandlerPool() @@ -59,14 +60,14 @@ CDExtraProtocolHandler* CDExtraProtocolHandlerPool::getHandler(unsigned int port if (proto) { if (proto->open()) { m_pool[port] = proto; - printf("New CDExtraProtocolHandler now on UDP port %u.\n", port); + CLog::logInfo("New CDExtraProtocolHandler now on UDP port %u.\n", port); } else { delete proto; proto = NULL; - printf("ERROR: Can't open new DExtra UDP port %u!\n", port); + CLog::logInfo("ERROR: Can't open new DExtra UDP port %u!\n", port); } } else - printf("ERROR: Can't allocate new CDExtraProtocolHandler at port %u\n", port); + CLog::logInfo("ERROR: Can't allocate new CDExtraProtocolHandler at port %u\n", port); return proto; } @@ -77,13 +78,13 @@ void CDExtraProtocolHandlerPool::release(CDExtraProtocolHandler *handler) if (it->second == handler) { it->second->close(); delete it->second; - printf("Releasing CDExtraProtocolHandler on port %u.\n", it->first); + CLog::logInfo("Releasing CDExtraProtocolHandler on port %u.\n", it->first); m_pool.erase(it); return; } } // we should never get here! - printf("ERROR: could not find CDExtraProtocolHander (port=%u) to release!\n", handler->getPort()); + CLog::logInfo("ERROR: could not find CDExtraProtocolHander (port=%u) to release!\n", handler->getPort()); } DEXTRA_TYPE CDExtraProtocolHandlerPool::read() diff --git a/DPlusAuthenticator.cpp b/DPlusAuthenticator.cpp index cc3d4a4..9a464e9 100644 --- a/DPlusAuthenticator.cpp +++ b/DPlusAuthenticator.cpp @@ -26,6 +26,7 @@ #include "DStarDefines.h" #include "Utils.h" #include "Defs.h" +#include "Log.h" const std::string OPENDSTAR_HOSTNAME = "auth.dstargateway.org"; const unsigned int OPENDSTAR_PORT = 20001U; @@ -65,7 +66,7 @@ void CDPlusAuthenticator::start() void* CDPlusAuthenticator::Entry() { - printf("Starting the D-Plus Authenticator thread"); + CLog::logInfo("Starting the D-Plus Authenticator thread"); authenticate(m_loginCallsign, OPENDSTAR_HOSTNAME, OPENDSTAR_PORT, '2', true); @@ -85,13 +86,13 @@ void* CDPlusAuthenticator::Entry() } catch (std::exception& e) { std::string message(e.what()); - printf("Exception raised in the D-Plus Authenticator thread - \"%s\"", message.c_str()); + CLog::logInfo("Exception raised in the D-Plus Authenticator thread - \"%s\"", message.c_str()); } catch (...) { - printf("Unknown exception raised in the D-Plus Authenticator thread"); + CLog::logInfo("Unknown exception raised in the D-Plus Authenticator thread"); } - printf("Stopping the D-Plus Authenticator thread"); + CLog::logInfo("Stopping the D-Plus Authenticator thread"); return NULL; } @@ -160,12 +161,12 @@ bool CDPlusAuthenticator::authenticate(const std::string& callsign, const std::s // Ensure that we get exactly len - 2U bytes from the TCP stream ret = read(socket, buffer + 2U, len - 2U); if (!ret) { - printf("Short read from %s:%u", hostname.c_str(), port); + CLog::logInfo("Short read from %s:%u", hostname.c_str(), port); break; } if ((buffer[1U] & 0xC0U) != 0xC0U || buffer[2U] != 0x01U) { - printf("Invalid packet received from %s:%u", hostname.c_str(), port); + CLog::logInfo("Invalid packet received from %s:%u", hostname.c_str(), port); CUtils::dump("Details:", buffer, len); break; } @@ -183,7 +184,7 @@ bool CDPlusAuthenticator::authenticate(const std::string& callsign, const std::s // An empty name or IP address or an inactive gateway/reflector is not written out if (address.length() > 0U && name.length() > 0U && !name.compare(0, 3, "XRF") == 0 && active && writeToCache){ if (name.compare(0, 3, "REF") == 0) - printf("D-Plus: %s\t%s", name.c_str(), address.c_str()); + CLog::logInfo("D-Plus: %s\t%s", name.c_str(), address.c_str()); name += " "; name = name.substr(LONG_CALLSIGN_LENGTH - 1U); @@ -195,7 +196,7 @@ bool CDPlusAuthenticator::authenticate(const std::string& callsign, const std::s ret = read(socket, buffer + 0U, 2U); } - printf("Registered with %s using callsign %s", hostname.c_str(), callsign.c_str()); + CLog::logInfo("Registered with %s using callsign %s", hostname.c_str(), callsign.c_str()); socket.close(); diff --git a/DPlusHandler.cpp b/DPlusHandler.cpp index adceda0..93bdf2e 100644 --- a/DPlusHandler.cpp +++ b/DPlusHandler.cpp @@ -279,7 +279,7 @@ void CDPlusHandler::process(const CPollData& poll) } // If we cannot find an existing link, we ignore the poll - wxLogMessage(("Incoming poll from unknown D-Plus dongle")); + CLog::logInfo(("Incoming poll from unknown D-Plus dongle")); } void CDPlusHandler::process(CConnectData& connect) @@ -321,7 +321,7 @@ void CDPlusHandler::process(CConnectData& connect) return; if (type != CT_LINK1) { - wxLogMessage(("Incoming D-Plus message from unknown source")); + CLog::logInfo(("Incoming D-Plus message from unknown source")); return; } @@ -352,7 +352,7 @@ void CDPlusHandler::process(CConnectData& connect) CConnectData connect(CT_LINK1, yourAddress, yourPort); m_incoming->writeConnect(connect); } else { - wxLogError("No space to add new D-Plus dongle, ignoring"); + CLog::logError("No space to add new D-Plus dongle, ignoring"); delete dplus; } } @@ -380,7 +380,7 @@ void CDPlusHandler::link(IReflectorCallback* handler, const std::string& repeate protoHandler->writeConnect(connect); m_stateChange = true; } else { - wxLogError(("No space to add new D-Plus reflector, ignoring")); + CLog::logError(("No space to add new D-Plus reflector, ignoring")); delete dplus; } } @@ -410,7 +410,7 @@ void CDPlusHandler::unlink(IReflectorCallback* handler, const std::string& calls if (exclude) { if (reflector->m_direction == DIR_OUTGOING && reflector->m_destination == handler && reflector->m_reflector != callsign) { - wxLogMessage("Removing outgoing D-Plus link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); + CLog::logInfo("Removing outgoing D-Plus link %s, %s", reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); if (reflector->m_linkState == DPLUS_LINKING || reflector->m_linkState == DPLUS_LINKED) { CConnectData connect(CT_UNLINK, reflector->m_yourAddress, DPLUS_PORT); @@ -428,7 +428,7 @@ void CDPlusHandler::unlink(IReflectorCallback* handler, const std::string& calls } } else { if (reflector->m_destination == handler && reflector->m_reflector == callsign) { - wxLogMessage(("Removing D-Plus link %s, %s"), reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); + CLog::logInfo(("Removing D-Plus link %s, %s"), reflector->m_repeater.c_str(), reflector->m_reflector.c_str()); if (reflector->m_linkState == DPLUS_LINKING || reflector->m_linkState == DPLUS_LINKED) { CConnectData connect(CT_UNLINK, reflector->m_yourAddress, DPLUS_PORT); @@ -474,7 +474,7 @@ void CDPlusHandler::unlink() CDPlusHandler* reflector = m_reflectors[i]; if (reflector != NULL) { if (!reflector->m_reflector.empty()) - wxLogMessage(("Unlinking from D-Plus reflector or dongle %s"), reflector->m_reflector.c_str()); + CLog::logInfo(("Unlinking from D-Plus reflector or dongle %s"), reflector->m_reflector.c_str()); CConnectData connect(CT_UNLINK, reflector->m_yourAddress, reflector->m_yourPort); reflector->m_handler->writeConnect(connect); @@ -514,10 +514,10 @@ void CDPlusHandler::gatewayUpdate(const std::string& gateway, const std::string& if (!reflector->m_reflector.empty() && reflector->m_reflector.substr(0, LONG_CALLSIGN_LENGTH - 1U) == gatewayBase) { if (!address.empty()) { // A new address, change the value - wxLogMessage("Changing IP address of D-Plus gateway or reflector %s to %s", gatewayBase.c_str(), address.c_str()); + CLog::logInfo("Changing IP address of D-Plus gateway or reflector %s to %s", gatewayBase.c_str(), address.c_str()); reflector->m_yourAddress.s_addr = ::inet_addr(address.c_str()); } else { - wxLogMessage("IP address for D-Plus gateway or reflector %s has been removed", gatewayBase.c_str()); + CLog::logInfo("IP address for D-Plus gateway or reflector %s has been removed", gatewayBase.c_str()); // No address, this probably shouldn't happen.... if (reflector->m_direction == DIR_OUTGOING && reflector->m_destination != NULL) @@ -567,7 +567,7 @@ void CDPlusHandler::processInt(CHeaderData& header) if (m_whiteList != NULL) { bool res = m_whiteList->isInList(my); if (!res) { - wxLogMessage(("%s rejected from D-Plus as not found in the white list"), my.c_str()); + CLog::logInfo(("%s rejected from D-Plus as not found in the white list"), my.c_str()); m_dPlusId = 0x00U; return; } @@ -576,7 +576,7 @@ void CDPlusHandler::processInt(CHeaderData& header) if (m_blackList != NULL) { bool res = m_blackList->isInList(my); if (res) { - wxLogMessage(("%s rejected from D-Plus as found in the black list"), my.c_str()); + CLog::logInfo(("%s rejected from D-Plus as found in the black list"), my.c_str()); m_dPlusId = 0x00U; return; } @@ -679,7 +679,7 @@ bool CDPlusHandler::processInt(CConnectData& connect, CD_TYPE type) switch (type) { case CT_ACK: if (m_linkState == DPLUS_LINKING) { - wxLogMessage(("D-Plus ACK message received from %s"), m_reflector.c_str()); + CLog::logInfo(("D-Plus ACK message received from %s"), m_reflector.c_str()); m_destination->linkUp(DP_DPLUS, m_reflector); m_stateChange = true; m_linkState = DPLUS_LINKED; @@ -691,7 +691,7 @@ bool CDPlusHandler::processInt(CConnectData& connect, CD_TYPE type) case CT_NAK: if (m_linkState == DPLUS_LINKING) { - wxLogMessage(("D-Plus NAK message received from %s"), m_reflector.c_str()); + CLog::logInfo(("D-Plus NAK message received from %s"), m_reflector.c_str()); m_destination->linkRefused(DP_DPLUS, m_reflector); CConnectData reply(CT_UNLINK, connect.getYourAddress(), connect.getYourPort()); m_handler->writeConnect(reply); @@ -701,7 +701,7 @@ bool CDPlusHandler::processInt(CConnectData& connect, CD_TYPE type) case CT_UNLINK: if (m_linkState == DPLUS_UNLINKING) { - wxLogMessage(("D-Plus disconnect acknowledgement received from %s"), m_reflector.c_str()); + CLog::logInfo(("D-Plus disconnect acknowledgement received from %s"), m_reflector.c_str()); m_destination->linkFailed(DP_DPLUS, m_reflector, false); m_stateChange = true; m_tryTimer.stop(); @@ -724,7 +724,7 @@ bool CDPlusHandler::processInt(CConnectData& connect, CD_TYPE type) switch (type) { case CT_LINK2: { m_reflector = connect.getRepeater(); - wxLogMessage(("D-Plus dongle link to %s has started"), m_reflector.c_str()); + CLog::logInfo(("D-Plus dongle link to %s has started"), m_reflector.c_str()); CConnectData reply(CT_ACK, m_yourAddress, m_yourPort); m_handler->writeConnect(reply); m_linkState = DPLUS_LINKED; @@ -734,7 +734,7 @@ bool CDPlusHandler::processInt(CConnectData& connect, CD_TYPE type) case CT_UNLINK: if (m_linkState == DPLUS_LINKED) { - wxLogMessage(("D-Plus dongle link to %s has ended (unlinked)"), m_reflector.c_str()); + CLog::logInfo(("D-Plus dongle link to %s has ended (unlinked)"), m_reflector.c_str()); m_stateChange = true; m_handler->writeConnect(connect); } @@ -769,13 +769,13 @@ bool CDPlusHandler::clockInt(unsigned int ms) if (!m_reflector.empty()) { switch (m_linkState) { case DPLUS_LINKING: - wxLogMessage(("D-Plus link to %s has failed to connect"), m_reflector.c_str()); + CLog::logInfo(("D-Plus link to %s has failed to connect"), m_reflector.c_str()); break; case DPLUS_LINKED: - wxLogMessage(("D-Plus link to %s has failed (poll inactivity)"), m_reflector.c_str()); + CLog::logInfo(("D-Plus link to %s has failed (poll inactivity)"), m_reflector.c_str()); break; case DPLUS_UNLINKING: - wxLogMessage(("D-Plus link to %s has failed to disconnect cleanly"), m_reflector.c_str()); + CLog::logInfo(("D-Plus link to %s has failed to disconnect cleanly"), m_reflector.c_str()); break; default: break; diff --git a/DPlusProtocolHandlerPool.cpp b/DPlusProtocolHandlerPool.cpp index 1bddc88..c29bf83 100644 --- a/DPlusProtocolHandlerPool.cpp +++ b/DPlusProtocolHandlerPool.cpp @@ -22,6 +22,7 @@ #include "DPlusProtocolHandlerPool.h" #include "Utils.h" +#include "Log.h" CDPlusProtocolHandlerPool::CDPlusProtocolHandlerPool(const unsigned int port, const std::string &addr) : m_basePort(port), @@ -29,7 +30,7 @@ m_address(addr) { assert(port > 0U); m_index = m_pool.end(); - printf("DExtra UDP port base = %u\n", port); + CLog::logInfo("DExtra UDP port base = %u\n", port); } CDPlusProtocolHandlerPool::~CDPlusProtocolHandlerPool() @@ -60,14 +61,14 @@ CDPlusProtocolHandler* CDPlusProtocolHandlerPool::getHandler(unsigned int port) if (proto) { if (proto->open()) { m_pool[port] = proto; - printf("New CDPlusProtocolHandler now on UDP port %u.\n", port); + CLog::logInfo("New CDPlusProtocolHandler now on UDP port %u.\n", port); } else { delete proto; proto = NULL; - printf("ERROR: Can't open new DPlus UDP port %u!\n", port); + CLog::logInfo("ERROR: Can't open new DPlus UDP port %u!\n", port); } } else - printf("ERROR: Can't allocate new CDPlusProtocolHandler at port %u\n", port); + CLog::logInfo("ERROR: Can't allocate new CDPlusProtocolHandler at port %u\n", port); return proto; } @@ -78,13 +79,13 @@ void CDPlusProtocolHandlerPool::release(CDPlusProtocolHandler *handler) if (it->second == handler) { it->second->close(); delete it->second; - printf("Releasing CDPlusProtocolHandler on port %u.\n", it->first); + CLog::logInfo("Releasing CDPlusProtocolHandler on port %u.\n", it->first); m_pool.erase(it); return; } } // we should never get here! - printf("ERROR: could not find CDPlusProtocolHander (port=%u) to release!\n", handler->getPort()); + CLog::logInfo("ERROR: could not find CDPlusProtocolHander (port=%u) to release!\n", handler->getPort()); } DPLUS_TYPE CDPlusProtocolHandlerPool::read() diff --git a/DStarGatewayApp.cpp b/DStarGatewayApp.cpp index b83996a..ddf0942 100644 --- a/DStarGatewayApp.cpp +++ b/DStarGatewayApp.cpp @@ -31,6 +31,7 @@ #include "IRCDDBMultiClient.h" #include "IRCDDBClient.h" #include "Utils.h" +#include "Version.h" #include "GitVersion.h" #include "RepeaterProtocolHandlerFactory.h" #include "Log.h" @@ -54,7 +55,7 @@ int main(int argc, char *argv[]) std::string cfgFile(argv[1]); CDStarGatewayApp gateway(cfgFile); - + if (!gateway.init()) { return 1; } @@ -81,7 +82,7 @@ void CDStarGatewayApp::run() { m_thread->Run(); m_thread->Wait(); - printf("exiting\n"); + CLog::logInfo("exiting\n"); } bool CDStarGatewayApp::createThread() @@ -92,12 +93,13 @@ bool CDStarGatewayApp::createThread() CDStarGatewayConfig config(m_configFile); if(!config.load()) { - wxLogError("FATAL: Invalid configuration"); + CLog::logError("FATAL: Invalid configuration"); return false; } Tpaths paths; config.getPaths(paths); + CLog::initialize(paths.logDir + "dstargateway.log", LS_INFO, true); m_thread = new CDStarGatewayThread(paths.logDir, paths.dataDir, ""); // Setup the gateway @@ -126,8 +128,7 @@ bool CDStarGatewayApp::createThread() for(unsigned int i=0; i < config.getIrcDDBCount(); i++) { TircDDB ircDDBConfig; config.getIrcDDB(i, ircDDBConfig); - std::cout << "ircDDB " << i + 1 << " set to " << ircDDBConfig.hostname << " username set to " << ircDDBConfig.username << " QuadNet " << ircDDBConfig.isQuadNet << std::endl; - + CLog::logInfo("ircDDB Network %d set to %s user: %s, Quadnet %d", i + 1,ircDDBConfig.hostname.c_str(), ircDDBConfig.username.c_str(), ircDDBConfig.isQuadNet); CIRCDDB * ircDDB = new CIRCDDBClient(ircDDBConfig.hostname, 9007U, ircDDBConfig.username, ircDDBConfig.password, std::string("DStarGateway") + std::string("-") + VERSION, gatewayConfig.address, ircDDBConfig.isQuadNet); clients.push_back(ircDDB); } @@ -135,7 +136,7 @@ bool CDStarGatewayApp::createThread() CIRCDDBMultiClient* multiClient = new CIRCDDBMultiClient(clients); bool res = multiClient->open(); if (!res) { - wxLogMessage("Cannot initialise the ircDDB protocol handler\n"); + CLog::logInfo("Cannot initialise the ircDDB protocol handler\n"); return false; } @@ -143,7 +144,7 @@ bool CDStarGatewayApp::createThread() // Setup the repeaters if(config.getRepeaterCount() == 0U) { - wxLogMessage("No repeater configured\n"); + CLog::logInfo("No repeater configured\n"); return false; } CRepeaterHandlerFactory repeaterProtocolFactory; @@ -189,7 +190,7 @@ bool CDStarGatewayApp::createThread() // repeater.resize(7, ' '); // repeater.push_back(band[0]); // m_thread->addGroup(callsign, logoff, repeater, info, permanent, usertimeout, callsignswitch, txmsgswitch, reflector); - // printf("Group %d: %s/%s using %s, \"%s\", perm: %s, timeout: %u mins, c/s switch: %s, msg switch: %s, Linked: %s\n", + // CLog::logInfo("Group %d: %s/%s using %s, \"%s\", perm: %s, timeout: %u mins, c/s switch: %s, msg switch: %s, Linked: %s\n", // i, callsign.c_str(), logoff.c_str(), repeater.c_str(), info.c_str(), permanent.c_str(), usertimeout, // SCS_GROUP_CALLSIGN==callsignswitch ? "Group" : "User", txmsgswitch ? "true" : "false", reflector.c_str()); // } @@ -199,7 +200,7 @@ bool CDStarGatewayApp::createThread() // std::string remotePassword; // unsigned int remotePort; // config.getRemote(remoteEnabled, remotePassword, remotePort); - // printf("Remote enabled set to %d, port set to %u\n", int(remoteEnabled), remotePort); + // CLog::logInfo("Remote enabled set to %d, port set to %u\n", int(remoteEnabled), remotePort); // m_thread->setRemote(remoteEnabled, remotePassword, remotePort); // m_thread->setAddress(address); diff --git a/DStarGatewayConfig.cpp b/DStarGatewayConfig.cpp index de21950..aed1ba1 100644 --- a/DStarGatewayConfig.cpp +++ b/DStarGatewayConfig.cpp @@ -25,6 +25,7 @@ #include "Utils.h" #include "DStarGatewayConfig.h" #include "DStarDefines.h" +#include "Log.h" CDStarGatewayConfig::CDStarGatewayConfig(const std::string &pathname) : m_fileName(pathname) @@ -34,6 +35,7 @@ CDStarGatewayConfig::CDStarGatewayConfig(const std::string &pathname) bool CDStarGatewayConfig::load() { + CLog::logInfo("Loading configuration from %s", m_fileName.c_str()); Config cfg; if(open(cfg) && loadGateway(cfg) @@ -49,6 +51,8 @@ bool CDStarGatewayConfig::load() return true; } + CLog::logError("Loading configuration from %s failed", m_fileName.c_str()); + return false; } @@ -189,12 +193,12 @@ bool CDStarGatewayConfig::loadRepeaters(const Config & cfg) isOk = true; } else { - std::cout << "Repeater " << i << " has an empty callsign" << std::endl ; + CLog::logError("Repeater %d has an empty callsign", i); } if (isOk && !isalpha(repeater->band[0])) { isOk = false; - std::cout << "Repeater " << i << " band is not a letter" << std::endl; + CLog::logError("Repeater %s band is not a letter", i); } if (isOk && repeater->address.length() == 0) { @@ -204,7 +208,6 @@ bool CDStarGatewayConfig::loadRepeaters(const Config & cfg) if(!isOk) { delete repeater; } else { - std::cout << "REPEATER: " << repeater->callsign << "-" << repeater->band << " " << repeater->address << ":" << repeater->port << std::endl; m_repeaters.push_back(repeater); } } @@ -241,7 +244,6 @@ bool CDStarGatewayConfig::loadIrcDDB(const Config & cfg) ircddb->isQuadNet = ircddb->hostname.find("openquad.net") != std::string::npos; this->m_ircDDB.push_back(ircddb); - std::cout << "IRCDDB: host=" << ircddb->hostname << " user=" << ircddb->username << " password=" << ircddb->password << std::endl; } if(this->m_ircDDB.size() == 0) {//no ircddb network specified? Default to openquad! @@ -251,7 +253,7 @@ bool CDStarGatewayConfig::loadIrcDDB(const Config & cfg) ircddb->username = m_gateway.callsign; ircddb->isQuadNet = true; this->m_ircDDB.push_back(ircddb); - std::cout << "No ircDDB networks configured, defaulting to IRCDDB: host=" << ircddb->hostname << " user=" << ircddb->username << " password=" << ircddb->password << "\n"; + CLog::logError("No ircDDB networks configured, defaulting to IRCDDB: host=%s user=%s", ircddb->hostname.c_str(), ircddb->username.c_str()); } return true; @@ -292,8 +294,6 @@ bool CDStarGatewayConfig::loadGateway(const Config & cfg) else if(lang == "norsk") m_gateway.language = TL_NORSK; else if(lang == "portugues") m_gateway.language = TL_PORTUGUES; - std::cout << "GATEWAY: callsign='" << m_gateway.callsign << "' listen address='" << m_gateway.address << std::endl; - CUtils::ToUpper(m_gateway.callsign); CUtils::clean(m_gateway.description1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .,&*()-+=@/?:;"); CUtils::clean(m_gateway.description2, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .,&*()-+=@/?:;"); @@ -305,7 +305,7 @@ bool CDStarGatewayConfig::loadGateway(const Config & cfg) bool CDStarGatewayConfig::open(Config & cfg) { if (m_fileName.size() < 1) { - printf("Configuration filename too short!\n"); + CLog::logError("Configuration filename too short!\n"); return false; } @@ -313,11 +313,11 @@ bool CDStarGatewayConfig::open(Config & cfg) cfg.readFile(m_fileName.c_str()); } catch(const FileIOException &fioex) { - printf("Can't read %s\n", m_fileName.c_str()); + CLog::logError("Can't read %s\n", m_fileName.c_str()); return false; } catch(const ParseException &pex) { - printf("Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError()); + CLog::logError("Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError()); return false; } @@ -386,7 +386,7 @@ bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path, if (cfg.lookupValue(path, value)) { int l = value.length(); if (lmax) { - std::cout << path << "=" << value << " has an inalid length, must be between " << min << " and " << max << " actual " << l << "\n"; + CLog::logWarning("%s has an invalid length, must be between %d and %d, actual %d", path.c_str(), min, max, l); return false; } } else @@ -418,8 +418,7 @@ bool CDStarGatewayConfig::get_value(const Config &cfg, const std::string &path, for(std::string s : allowedValues) { message << s << ", "; } - message << std::endl; - std::cout << message.str(); + CLog::logWarning(message.str()); } return ret; diff --git a/DStarGatewayThread.cpp b/DStarGatewayThread.cpp index 8f74680..eff00b5 100644 --- a/DStarGatewayThread.cpp +++ b/DStarGatewayThread.cpp @@ -157,7 +157,7 @@ void* CDStarGatewayThread::Entry() fullName += fullName + m_name; } CUtils::truncateFile(fullName); - wxLogMessage("Truncating %s", fullName.c_str()); + CLog::logInfo("Truncating %s", fullName.c_str()); #ifdef USE_STARNET // Truncate the old StarNet.log file @@ -166,7 +166,7 @@ void* CDStarGatewayThread::Entry() fullName += fullName + m_name; } CUtils::truncateFile(fullName); - wxLogMessage("Truncating %s", fullName.c_str()); + CLog::logInfo("Truncating %s", fullName.c_str()); #endif std::string dextraAddress = m_dextraEnabled ? m_gatewayAddress : LOOPBACK_ADDRESS; @@ -178,7 +178,7 @@ void* CDStarGatewayThread::Entry() CDExtraHandler::setDExtraProtocolHandlerPool(m_dextraPool); } else { - wxLogError("Failed to allocate incoming DExtra handler\n"); + CLog::logError("Failed to allocate incoming DExtra handler\n"); } @@ -189,7 +189,7 @@ void* CDStarGatewayThread::Entry() CDPlusHandler::setDPlusProtocolIncoming(dplusHandler); CDPlusHandler::setDPlusProtocolHandlerPool(m_dplusPool); } else { - wxLogError("Failed to allocate incoming DPlus handler\n"); + CLog::logError("Failed to allocate incoming DPlus handler\n"); } std::string dcsAddress = m_dcsEnabled ? m_gatewayAddress : LOOPBACK_ADDRESS; @@ -199,13 +199,13 @@ void* CDStarGatewayThread::Entry() CDCSHandler::setDCSProtocolIncoming(dcsHandler); CDCSHandler::setDCSProtocolHandlerPool(m_dcsPool); } else { - wxLogError("Failed to allocate incoming DCS handler\n"); + CLog::logError("Failed to allocate incoming DCS handler\n"); } m_g2Handler = new CG2ProtocolHandler(G2_DV_PORT, m_gatewayAddress); bool ret = m_g2Handler->open(); if (!ret) { - wxLogError("Could not open the G2 protocol handler"); + CLog::logError("Could not open the G2 protocol handler"); delete m_g2Handler; m_g2Handler = NULL; } @@ -226,7 +226,7 @@ void* CDStarGatewayThread::Entry() m_stopped = false; - wxLogMessage("Starting the ircDDB Gateway thread"); + CLog::logInfo("Starting the ircDDB Gateway thread"); CHeaderLogger* headerLogger = NULL; if (m_logEnabled) { @@ -427,13 +427,13 @@ void* CDStarGatewayThread::Entry() } catch (std::exception& e) { std::string message(e.what()); - wxLogError("Exception raised in the main thread - \"%s\"", message.c_str()); + CLog::logError("Exception raised in the main thread - \"%s\"", message.c_str()); } catch (...) { - wxLogError("Unknown exception raised in the main thread"); + CLog::logError("Unknown exception raised in the main thread"); } - wxLogMessage("Stopping the ircDDB Gateway thread"); + CLog::logInfo("Stopping the ircDDB Gateway thread"); // Unlink from all reflectors CDExtraHandler::unlink(); @@ -526,7 +526,7 @@ void CDStarGatewayThread::addRepeater(const std::string& callsign, const std::st // Add a fixed address and protocol for the local repeaters m_cache.updateRepeater(repeater, m_gatewayCallsign, "127.0.0.1", DP_LOOPBACK, true, true); - wxLogMessage("Adding %s to the cache as a local repeater", repeater.c_str()); + CLog::logInfo("Adding %s to the cache as a local repeater", repeater.c_str()); } #ifdef USE_STARNET @@ -615,14 +615,14 @@ void CDStarGatewayThread::setCCS(bool enabled, const std::string& host) wxFileName fileName(wxFileName::GetHomeDir(), CCS_HOSTS_FILE_NAME); if (!fileName.IsFileReadable()) { - wxLogMessage(wxT("File %s not readable"), fileName.GetFullPath().c_str()); + CLog::logInfo(wxT("File %s not readable"), fileName.GetFullPath().c_str()); #if defined(__WINDOWS__) fileName.Assign(::wxGetCwd(), CCS_HOSTS_FILE_NAME); #else fileName.Assign(wxT(m_dataDir), CCS_HOSTS_FILE_NAME); #endif if (!fileName.IsFileReadable()) { - wxLogMessage(wxT("File %s not readable"), fileName.GetFullPath().c_str()); + CLog::logInfo(wxT("File %s not readable"), fileName.GetFullPath().c_str()); m_ccsEnabled = false; return; } @@ -713,19 +713,19 @@ void CDStarGatewayThread::processIrcDDB() case 0: case 10: if (m_lastStatus != IS_DISCONNECTED) { - wxLogInfo("Disconnected from ircDDB"); + CLog::logInfo("Disconnected from ircDDB"); m_lastStatus = IS_DISCONNECTED; } break; case 7: if (m_lastStatus != IS_CONNECTED) { - wxLogInfo("Connected to ircDDB"); + CLog::logInfo("Connected to ircDDB"); m_lastStatus = IS_CONNECTED; } break; default: if (m_lastStatus != IS_CONNECTING) { - wxLogInfo("Connecting to ircDDB"); + CLog::logInfo("Connecting to ircDDB"); m_lastStatus = IS_CONNECTING; } break; @@ -746,13 +746,13 @@ void CDStarGatewayThread::processIrcDDB() break; if (!address.empty()) { - wxLogMessage("USER: %s %s %s %s", user.c_str(), repeater.c_str(), gateway.c_str(), address.c_str()); + CLog::logInfo("USER: %s %s %s %s", user.c_str(), repeater.c_str(), gateway.c_str(), address.c_str()); m_cache.updateUser(user, repeater, gateway, address, timestamp, DP_DEXTRA, false, false); #if defined(ENABLE_NAT_TRAVERSAL) m_natTraversal->traverseNatG2(address); #endif } else { - wxLogMessage("USER: %s NOT FOUND", user.c_str()); + CLog::logInfo("USER: %s NOT FOUND", user.c_str()); } } break; @@ -765,13 +765,13 @@ void CDStarGatewayThread::processIrcDDB() CRepeaterHandler::resolveRepeater(repeater, gateway, address, DP_DEXTRA); if (!address.empty()) { - wxLogMessage("REPEATER: %s %s %s", repeater.c_str(), gateway.c_str(), address.c_str()); + CLog::logInfo("REPEATER: %s %s %s", repeater.c_str(), gateway.c_str(), address.c_str()); m_cache.updateRepeater(repeater, gateway, address, DP_DEXTRA, false, false); #if defined(ENABLE_NAT_TRAVERSAL) m_natTraversal->traverseNatG2(address); #endif } else { - wxLogMessage("REPEATER: %s NOT FOUND", repeater.c_str()); + CLog::logInfo("REPEATER: %s NOT FOUND", repeater.c_str()); } } break; @@ -785,13 +785,13 @@ void CDStarGatewayThread::processIrcDDB() CDExtraHandler::gatewayUpdate(gateway, address); CDPlusHandler::gatewayUpdate(gateway, address); if (!address.empty()) { - wxLogMessage("GATEWAY: %s %s", gateway.c_str(), address.c_str()); + CLog::logInfo("GATEWAY: %s %s", gateway.c_str(), address.c_str()); m_cache.updateGateway(gateway, address, DP_DEXTRA, false, false); #if defined(ENABLE_NAT_TRAVERSAL) m_natTraversal->traverseNatG2(address); #endif } else { - wxLogMessage("GATEWAY: %s NOT FOUND", gateway.c_str()); + CLog::logInfo("GATEWAY: %s NOT FOUND", gateway.c_str()); } } break; @@ -832,7 +832,7 @@ void CDStarGatewayThread::processRepeater(IRepeaterProtocolHandler* handler) if (repeater != user) { CRepeaterHandler* handler = CRepeaterHandler::findDVRepeater(repeater); if (handler == NULL) - wxLogMessage("Heard received from unknown repeater, %s", repeater.c_str()); + CLog::logInfo("Heard received from unknown repeater, %s", repeater.c_str()); else handler->processRepeater(*heard); @@ -845,11 +845,11 @@ void CDStarGatewayThread::processRepeater(IRepeaterProtocolHandler* handler) case RT_HEADER: { CHeaderData* header = handler->readHeader(); if (header != NULL) { - // wxLogMessage(wxT("Repeater header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3()); + // CLog::logInfo(wxT("Repeater header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3()); CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*header); if (repeater == NULL) - wxLogMessage("Header received from unknown repeater, %s", header->getRptCall1().c_str()); + CLog::logInfo("Header received from unknown repeater, %s", header->getRptCall1().c_str()); else repeater->processRepeater(*header); @@ -873,11 +873,11 @@ void CDStarGatewayThread::processRepeater(IRepeaterProtocolHandler* handler) case RT_BUSY_HEADER: { CHeaderData* header = handler->readBusyHeader(); if (header != NULL) { - // wxLogMessage(wxT("Repeater busy header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3()); + // CLog::logInfo(wxT("Repeater busy header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3()); CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*header); if (repeater == NULL) - wxLogMessage("Busy header received from unknown repeater, %s", header->getRptCall1().c_str()); + CLog::logInfo("Busy header received from unknown repeater, %s", header->getRptCall1().c_str()); else repeater->processBusy(*header); @@ -901,11 +901,11 @@ void CDStarGatewayThread::processRepeater(IRepeaterProtocolHandler* handler) case RT_DD: { CDDData* data = handler->readDD(); if (data != NULL) { - // wxLogMessage(wxT("DD header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), data->getMyCall1().c_str(), data->getMyCall2().c_str(), data->getYourCall().c_str(), data->getRptCall1().c_str(), data->getRptCall2().c_str(), data->getFlag1(), data->getFlag2(), data->getFlag3()); + // CLog::logInfo(wxT("DD header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), data->getMyCall1().c_str(), data->getMyCall2().c_str(), data->getYourCall().c_str(), data->getRptCall1().c_str(), data->getRptCall2().c_str(), data->getFlag1(), data->getFlag2(), data->getFlag3()); CRepeaterHandler* repeater = CRepeaterHandler::findDDRepeater(); if (repeater == NULL) - wxLogMessage("DD data received from unknown DD repeater, %s", data->getRptCall1().c_str()); + CLog::logInfo("DD data received from unknown DD repeater, %s", data->getRptCall1().c_str()); else repeater->processRepeater(*data); @@ -947,7 +947,7 @@ void CDStarGatewayThread::processDExtra() case DE_HEADER: { CHeaderData* header = m_dextraPool->readHeader(); if (header != NULL) { - // wxLogMessage(wxT("DExtra header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str()); + // CLog::logInfo(wxT("DExtra header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str()); CDExtraHandler::process(*header); delete header; } @@ -996,7 +996,7 @@ void CDStarGatewayThread::processDPlus() case DP_HEADER: { CHeaderData* header = m_dplusPool->readHeader(); if (header != NULL) { - // wxLogMessage(wxT("D-Plus header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str()); + // CLog::logInfo(wxT("D-Plus header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str()); CDPlusHandler::process(*header); delete header; } @@ -1045,7 +1045,7 @@ void CDStarGatewayThread::processDCS() case DC_DATA: { CAMBEData* data = m_dcsPool->readData(); if (data != NULL) { - // wxLogMessage(wxT("DCS header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str()); + // CLog::logInfo(wxT("DCS header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str()); CDCSHandler::process(*data); delete data; } @@ -1067,7 +1067,7 @@ void CDStarGatewayThread::processG2() case GT_HEADER: { CHeaderData* header = m_g2Handler->readHeader(); if (header != NULL) { - // wxLogMessage(wxT("G2 header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3()); + // CLog::logInfo(wxT("G2 header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3()); CG2Handler::process(*header); delete header; } @@ -1096,7 +1096,7 @@ void CDStarGatewayThread::processDD() if (data == NULL) return; - // wxLogMessage(wxT("DD header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), data->getMyCall1().c_str(), data->getMyCall2().c_str(), data->getYourCall().c_str(), data->getRptCall1().c_str(), data->getRptCall2().c_str(), data->getFlag1(), data->getFlag2(), data->getFlag3()); + // CLog::logInfo(wxT("DD header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), data->getMyCall1().c_str(), data->getMyCall2().c_str(), data->getYourCall().c_str(), data->getRptCall1().c_str(), data->getRptCall2().c_str(), data->getFlag1(), data->getFlag2(), data->getFlag3()); delete data; } @@ -1147,7 +1147,7 @@ void CDStarGatewayThread::loadReflectors(std::string hostFileName, DSTAR_PROTOCO addrText = CStringUtils::string_format("%u.%u.%u.%u", ucp[0U] & 0xFFU, ucp[1U] & 0xFFU, ucp[2U] & 0xFFU, ucp[3U] & 0xFFU); if (lock) - wxLogMessage("Locking %s to %s", reflector.c_str(), addrText.c_str()); + CLog::logInfo("Locking %s to %s", reflector.c_str(), addrText.c_str()); reflector.resize(LONG_CALLSIGN_LENGTH - 1U, ' '); reflector += "G"; @@ -1174,7 +1174,7 @@ void CDStarGatewayThread::loadReflectors(std::string hostFileName, DSTAR_PROTOCO break; } - wxLogMessage("Loaded %u of %u %s hosts from %s", count, hostFile.getCount(), protoString.c_str() , hostFileName.c_str()); + CLog::logInfo("Loaded %u of %u %s hosts from %s", count, hostFile.getCount(), protoString.c_str() , hostFileName.c_str()); } void CDStarGatewayThread::writeStatus() @@ -1190,7 +1190,7 @@ void CDStarGatewayThread::writeStatus() std::ofstream file; file.open(fullName, std::fstream::trunc); if (!file.is_open()) { - wxLogError("Unable to open %s for writing", fullName.c_str()); + CLog::logError("Unable to open %s for writing", fullName.c_str()); return; } @@ -1270,7 +1270,7 @@ void CDStarGatewayThread::readStatusFile(const std::string& filename, unsigned i } if(var != text) { - wxLogMessage("Status %u message set to \"%s\"", n + 1U, text.c_str()); + CLog::logInfo("Status %u message set to \"%s\"", n + 1U, text.c_str()); CStatusData statusData(text, n); CRepeaterHandler::writeStatus(statusData); var = text; diff --git a/DummyRepeaterProtocolHandler.cpp b/DummyRepeaterProtocolHandler.cpp index d4d732a..c9af067 100644 --- a/DummyRepeaterProtocolHandler.cpp +++ b/DummyRepeaterProtocolHandler.cpp @@ -41,7 +41,7 @@ bool CDummyRepeaterProtocolHandler::writeHeader(CHeaderData& header) unsigned char buffer[50U]; unsigned int length = header.getHBRepeaterData(buffer, 50U, true); - wxLogMessage("Sending Header to port: %u, id: %04X", header.getYourPort(), header.getId()); + CLog::logInfo("Sending Header to port: %u, id: %04X", header.getYourPort(), header.getId()); CUtils::dump("Data", buffer + 8U, length - 8U); @@ -53,7 +53,7 @@ bool CDummyRepeaterProtocolHandler::writeAMBE(CAMBEData& data) unsigned char buffer[30U]; unsigned int length = data.getHBRepeaterData(buffer, 30U); - wxLogMessage("Sending AMBE to port: %u, seq: %02X, id: %04X", data.getYourPort(), data.getSeq(), data.getId()); + CLog::logInfo("Sending AMBE to port: %u, seq: %02X, id: %04X", data.getYourPort(), data.getSeq(), data.getId()); CUtils::dump("Data", buffer + 9U, length - 9U); diff --git a/EchoUnit.cpp b/EchoUnit.cpp index cb5d408..599e14e 100644 --- a/EchoUnit.cpp +++ b/EchoUnit.cpp @@ -24,6 +24,7 @@ #include "EchoUnit.h" #include "Defs.h" #include "Utils.h" +#include "Log.h" const unsigned int MAX_FRAMES = 60U * DSTAR_FRAMES_PER_SEC; @@ -73,7 +74,7 @@ void CEchoUnit::writeData(const CAMBEData& data) } if (data.isEnd()) { - printf("Received %.1f secs of audio from %s for echoing\n", float(m_in) / float(DSTAR_FRAMES_PER_SEC), m_header->getMyCall1().c_str()); + CLog::logInfo("Received %.1f secs of audio from %s for echoing\n", float(m_in) / float(DSTAR_FRAMES_PER_SEC), m_header->getMyCall1().c_str()); m_timer.start(); m_status = ES_WAIT; @@ -85,7 +86,7 @@ void CEchoUnit::end() if (m_status != ES_RECEIVE) return; - printf("Received %.1f secs of audio from %s for echoing\n", float(m_in) / float(DSTAR_FRAMES_PER_SEC), m_header->getMyCall1().c_str()); + CLog::logInfo("Received %.1f secs of audio from %s for echoing\n", float(m_in) / float(DSTAR_FRAMES_PER_SEC), m_header->getMyCall1().c_str()); m_timer.start(); m_status = ES_WAIT; diff --git a/G2Handler.cpp b/G2Handler.cpp index ec9e858..ddd46fd 100644 --- a/G2Handler.cpp +++ b/G2Handler.cpp @@ -78,7 +78,7 @@ void CG2Handler::process(CHeaderData& header) unsigned char flag1 = header.getFlag1(); if (flag1 == 0x01) { // Don't check the incoming stream - // wxLogMessage(wxT("G2 busy message received")); + // CLog::logInfo(wxT("G2 busy message received")); return; } @@ -114,7 +114,7 @@ void CG2Handler::process(CHeaderData& header) // Find the destination repeater CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(header.getRptCall2()); if (repeater == NULL) { - wxLogMessage("Incoming G2 header from %s to unknown repeater - %s", header.getMyCall1().c_str(), header.getRptCall2().c_str()); + CLog::logInfo("Incoming G2 header from %s to unknown repeater - %s", header.getMyCall1().c_str(), header.getRptCall2().c_str()); return; // Not found, ignore } @@ -133,7 +133,7 @@ void CG2Handler::process(CHeaderData& header) } } - wxLogMessage("No space to add new G2 route, ignoring"); + CLog::logInfo("No space to add new G2 route, ignoring"); delete route; } @@ -200,7 +200,7 @@ bool CG2Handler::clockInt(unsigned int ms) m_inactivityTimer.clock(ms); if (m_inactivityTimer.isRunning() && m_inactivityTimer.hasExpired()) { - wxLogMessage("Inactivity timeout for a G2 route has expired"); + CLog::logInfo("Inactivity timeout for a G2 route has expired"); return true; } diff --git a/G2ProtocolHandler.cpp b/G2ProtocolHandler.cpp index 156b759..8047c89 100644 --- a/G2ProtocolHandler.cpp +++ b/G2ProtocolHandler.cpp @@ -18,8 +18,10 @@ */ #include + #include "G2ProtocolHandler.h" #include "Utils.h" +#include "Log.h" // #define DUMP_TX @@ -109,11 +111,11 @@ bool CG2ProtocolHandler::readPackets() // save the incoming port (this is to enable mobile hotspots) if (portmap.end() == portmap.find(m_address.s_addr)) { - printf("new address %s on port %u\n", inet_ntoa(m_address), m_port); + CLog::logInfo("new address %s on port %u\n", inet_ntoa(m_address), m_port); portmap[m_address.s_addr] = m_port; } else { if (portmap[m_address.s_addr] != m_port) { - printf("new port for %s is %u, was %u\n", inet_ntoa(m_address), m_port, portmap[m_address.s_addr]); + CLog::logInfo("new port for %s is %u, was %u\n", inet_ntoa(m_address), m_port, portmap[m_address.s_addr]); portmap[m_address.s_addr] = m_port; } } diff --git a/HBRepeaterProtocolHandler.cpp b/HBRepeaterProtocolHandler.cpp index 443ad73..556c194 100644 --- a/HBRepeaterProtocolHandler.cpp +++ b/HBRepeaterProtocolHandler.cpp @@ -201,7 +201,7 @@ CHeaderData* CHBRepeaterProtocolHandler::readHeader() bool res = header->setHBRepeaterData(m_buffer, m_length, true, m_address, m_port); if (!res) { - wxLogError("Invalid checksum from the repeater"); + CLog::logError("Invalid checksum from the repeater"); delete header; return NULL; } @@ -218,7 +218,7 @@ CAMBEData* CHBRepeaterProtocolHandler::readAMBE() bool res = data->setHBRepeaterData(m_buffer, m_length, m_address, m_port); if (!res) { - wxLogError("Invalid AMBE data from the repeater"); + CLog::logError("Invalid AMBE data from the repeater"); delete data; return NULL; } @@ -235,7 +235,7 @@ CHeaderData* CHBRepeaterProtocolHandler::readBusyHeader() bool res = header->setHBRepeaterData(m_buffer, m_length, true, m_address, m_port); if (!res) { - wxLogError("Invalid checksum from the repeater"); + CLog::logError("Invalid checksum from the repeater"); delete header; return NULL; } @@ -252,7 +252,7 @@ CAMBEData* CHBRepeaterProtocolHandler::readBusyAMBE() bool res = data->setHBRepeaterData(m_buffer, m_length, m_address, m_port); if (!res) { - wxLogError("Invalid AMBE data from the repeater"); + CLog::logError("Invalid AMBE data from the repeater"); delete data; return NULL; } @@ -274,7 +274,7 @@ CDDData* CHBRepeaterProtocolHandler::readDD() bool res = data->setHBRepeaterData(m_buffer, m_length, m_address, m_port); if (!res) { - wxLogError("Invalid DD data from the repeater"); + CLog::logError("Invalid DD data from the repeater"); delete data; return NULL; } diff --git a/HeaderLogger.cpp b/HeaderLogger.cpp index e3fbc12..bd78d68 100644 --- a/HeaderLogger.cpp +++ b/HeaderLogger.cpp @@ -52,7 +52,7 @@ bool CHeaderLogger::open() m_file.open(fullName, std::ios::app); if (!m_file.is_open()) { - wxLogError("Cannot open %s file for appending", fullName.c_str()); + CLog::logError("Cannot open %s file for appending", fullName.c_str()); return false; } diff --git a/HostFile.cpp b/HostFile.cpp index f7824a1..0c88ff7 100644 --- a/HostFile.cpp +++ b/HostFile.cpp @@ -39,7 +39,7 @@ m_locks() return; if (logging) - wxLogMessage("Reading %s", fileName.c_str()); + CLog::logInfo("Reading %s", fileName.c_str()); while(!file.eof()) { std::string line; diff --git a/IRCClient.cpp b/IRCClient.cpp index 91c9e8e..dcdc3cf 100644 --- a/IRCClient.cpp +++ b/IRCClient.cpp @@ -31,6 +31,7 @@ along with this program. If not, see . #include "IRCClient.h" #include "Utils.h" +#include "Log.h" IRCClient::IRCClient(IRCApplication *app, const std::string& update_channel, const std::string& hostName, unsigned int port, const std::string& callsign, const std::string& password, const std::string& versionInfo, const std::string& localAddr) @@ -87,7 +88,7 @@ void IRCClient::Entry() int result = CUtils::getAllIPV4Addresses(m_local_addr, 0, &numAddr, &myaddr, 1); if (result || 1!=numAddr) { - printf("IRCClient::Entry: local address not parseable, using 0.0.0.0\n"); + CLog::logInfo("IRCClient::Entry: local address not parseable, using 0.0.0.0\n"); memset(&myaddr, 0, sizeof(struct sockaddr_in)); } @@ -98,7 +99,7 @@ void IRCClient::Entry() switch (state) { case 0: if (m_terminateThread) { - printf("IRCClient::Entry: thread terminated at state=%d\n", state); + CLog::logInfo("IRCClient::Entry: thread terminated at state=%d\n", state); return; } @@ -106,7 +107,7 @@ void IRCClient::Entry() timer = 30; if (0 == CUtils::getAllIPV4Addresses(m_host_name, m_port, &numAddr, addr, MAXIPV4ADDR)) { - printf("IRCClient::Entry: number of DNS entries %d\n", numAddr); + CLog::logInfo("IRCClient::Entry: number of DNS entries %d\n", numAddr); if (numAddr > 0) { currentAddr = 0; state = 1; @@ -118,7 +119,7 @@ void IRCClient::Entry() case 1: if (m_terminateThread) { - printf("IRCClient::Entry: thread terminated at state=%d\n", state); + CLog::logInfo("IRCClient::Entry: thread terminated at state=%d\n", state); return; } @@ -126,12 +127,12 @@ void IRCClient::Entry() sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock < 0) { - printf("IRCClient::Entry: socket\n"); + CLog::logInfo("IRCClient::Entry: socket\n"); timer = 30; state = 0; } else { if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { - printf("IRCClient::Entry: fcntl\n"); + CLog::logInfo("IRCClient::Entry: fcntl\n"); close(sock); timer = 30; state = 0; @@ -139,12 +140,12 @@ void IRCClient::Entry() unsigned char * h = (unsigned char *) &(myaddr.sin_addr); if (h[0] || h[1] || h[2] || h[3]) - printf("IRCClient::Entry: bind: local address %d.%d.%d.%d\n", h[0], h[1], h[2], h[3]); + CLog::logInfo("IRCClient::Entry: bind: local address %d.%d.%d.%d\n", h[0], h[1], h[2], h[3]); int res = bind(sock, (struct sockaddr *)&myaddr, sizeof (struct sockaddr_in)); if (res) { - printf("IRCClient::Entry: bind\n"); + CLog::logInfo("IRCClient::Entry: bind\n"); close(sock); state = 0; timer = 30; @@ -152,20 +153,20 @@ void IRCClient::Entry() } h = (unsigned char *) &(addr[currentAddr].sin_addr); - printf("IRCClient::Entry: trying to connect to %d.%d.%d.%d\n", h[0], h[1], h[2], h[3]); + CLog::logInfo("IRCClient::Entry: trying to connect to %d.%d.%d.%d\n", h[0], h[1], h[2], h[3]); res = connect(sock, (struct sockaddr *)(addr + currentAddr), sizeof (struct sockaddr_in)); if (res == 0) { - printf("IRCClient::Entry: connected\n"); + CLog::logInfo("IRCClient::Entry: connected\n"); state = 4; } else { if (errno == EINPROGRESS) { - printf("IRCClient::Entry: connect in progress\n"); + CLog::logInfo("IRCClient::Entry: connect in progress\n"); state = 3; timer = 10; // 5 second timeout } else { - printf("IRCClient::Entry: connect\n"); + CLog::logInfo("IRCClient::Entry: connect\n"); close(sock); currentAddr++; if (currentAddr >= numAddr) { @@ -194,7 +195,7 @@ void IRCClient::Entry() int res = select(sock+1, NULL, &myset, NULL, &tv); if (res < 0) { - printf("IRCClient::Entry: select\n"); + CLog::logInfo("IRCClient::Entry: select\n"); close(sock); state = 0; timer = 30; @@ -207,13 +208,13 @@ void IRCClient::Entry() val_len = sizeof value; if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *) &value, &val_len) < 0) { - printf("IRCClient::Entry: getsockopt\n"); + CLog::logInfo("IRCClient::Entry: getsockopt\n"); close(sock); state = 0; timer = 30; } else { if (value) { - printf("IRCClient::Entry: SO_ERROR=%d\n", value); + CLog::logInfo("IRCClient::Entry: SO_ERROR=%d\n", value); close(sock); currentAddr ++; if (currentAddr >= numAddr) { @@ -224,13 +225,13 @@ void IRCClient::Entry() timer = 2; } } else { - printf("IRCClient::Entry: connected2\n"); + CLog::logInfo("IRCClient::Entry: connected2\n"); state = 4; } } } else if (timer == 0) { // select timeout and timer timeout - printf("IRCClient::Entry: connect timeout\n"); + CLog::logInfo("IRCClient::Entry: connect timeout\n"); close(sock); currentAddr ++; if (currentAddr >= numAddr) { @@ -283,12 +284,12 @@ void IRCClient::Entry() int r = send(sock, buf, len, 0); if (r != len) { - printf("IRCClient::Entry: short write %d < %d\n", r, len); + CLog::logInfo("IRCClient::Entry: short write %d < %d\n", r, len); timer = 0; state = 6; } } else { - printf("IRCClient::Entry: no NL at end, len=%d\n", len); + CLog::logInfo("IRCClient::Entry: no NL at end, len=%d\n", len); timer = 0; state = 6; } @@ -316,7 +317,7 @@ void IRCClient::Entry() close(sock); if (m_terminateThread) { // request to end the thread - printf("IRCClient::Entry: thread terminated at state=%d\n", state); + CLog::logInfo("IRCClient::Entry: thread terminated at state=%d\n", state); return; } timer = 30; diff --git a/IRCDDBApp.cpp b/IRCDDBApp.cpp index 2757e81..96ac2a2 100644 --- a/IRCDDBApp.cpp +++ b/IRCDDBApp.cpp @@ -30,6 +30,7 @@ along with this program. If not, see . #include "IRCDDBApp.h" #include "Utils.h" +#include "Log.h" class IRCDDBAppUserObject { @@ -180,7 +181,7 @@ void IRCDDBApp::rptrQTH(const std::string& callsign, double latitude, double lon d->moduleQTH[cs] = cs + std::string(" ") + pos + std::string(" ") + d1 + std::string(" ") + d2; - printf("QTH: %s\n", d->moduleQTH[cs].c_str()); + CLog::logInfo("QTH: %s\n", d->moduleQTH[cs].c_str()); std::string url = infoURL; @@ -190,7 +191,7 @@ void IRCDDBApp::rptrQTH(const std::string& callsign, double latitude, double lon if (url.size()) { d->moduleURL[cs] = cs + std::string(" ") + url; - printf("URL: %s\n", d->moduleURL[cs].c_str()); + CLog::logInfo("URL: %s\n", d->moduleURL[cs].c_str()); } d->moduleQTHURLMutex.unlock(); @@ -209,7 +210,7 @@ void IRCDDBApp::rptrQRG(const std::string& callsign, double txFrequency, double d->moduleQRGMutex.lock(); d->moduleQRG[cs] = cs + std::string(" ") + f; - printf("QRG: %s\n", d->moduleQRG[cs].c_str()); + CLog::logInfo("QRG: %s\n", d->moduleQRG[cs].c_str()); d->moduleQRGMutex.unlock(); d->infoTimer = 5; // send info in 5 seconds @@ -257,7 +258,7 @@ IRCDDB_RESPONSE_TYPE IRCDDBApp::getReplyMessageType() if (0 == msgType.compare("IDRT_GATEWAY")) return IDRT_GATEWAY; - printf("IRCDDBApp::getMessageType: unknown msg type: %s\n", msgType.c_str()); + CLog::logInfo("IRCDDBApp::getMessageType: unknown msg type: %s\n", msgType.c_str()); return IDRT_NONE; } @@ -337,7 +338,7 @@ void IRCDDBApp::userLeave(const std::string& nick) if (d->currentServer.size()) { if (d->user.count(d->myNick) != 1) { - printf("IRCDDBApp::userLeave: could not find own nick\n"); + CLog::logInfo("IRCDDBApp::userLeave: could not find own nick\n"); d->userMapMutex.unlock(); return; } @@ -368,13 +369,13 @@ void IRCDDBApp::userListReset() void IRCDDBApp::setCurrentNick(const std::string& nick) { d->myNick = nick; - printf("IRCDDBApp::setCurrentNick %s\n", nick.c_str()); + CLog::logInfo("IRCDDBApp::setCurrentNick %s\n", nick.c_str()); } void IRCDDBApp::setBestServer(const std::string& ircUser) { d->bestServer = ircUser; - printf("IRCDDBApp::setBestServer %s\n", ircUser.c_str()); + CLog::logInfo("IRCDDBApp::setBestServer %s\n", ircUser.c_str()); } void IRCDDBApp::setTopic(const std::string& topic) @@ -667,7 +668,7 @@ void IRCDDBApp::doNotFound(std::string& msg, std::string& retval) tableID = std::stoi(tk); if (tableID<0 || tableID>=numberOfTables) { - printf("invalid table ID %d\n", tableID); + CLog::logInfo("invalid table ID %d\n", tableID); return; } @@ -698,7 +699,7 @@ void IRCDDBApp::doUpdate(std::string& msg) if (std::regex_match(tk, d->tablePattern)) { tableID = std::stoi(tk); if ((tableID < 0) || (tableID >= numberOfTables)) { - printf("invalid table ID %d\n", tableID); + CLog::logInfo("invalid table ID %d\n", tableID); return; } @@ -899,7 +900,7 @@ void IRCDDBApp::Entry() break; case 2: // choose server - printf("IRCDDBApp: state=2 choose new 's-'-user\n"); + CLog::logInfo("IRCDDBApp: state=2 choose new 's-'-user\n"); if (NULL == getSendQ()) d->state = 10; else { @@ -925,7 +926,7 @@ void IRCDDBApp::Entry() if (sendlistTableID < 0) d->state = 6; // end of sendlist else { - printf("IRCDDBApp: state=3 tableID=%d\n", sendlistTableID); + CLog::logInfo("IRCDDBApp: state=3 tableID=%d\n", sendlistTableID); d->state = 4; // send "SENDLIST" d->timer = 900; // 15 minutes max for update } @@ -964,7 +965,7 @@ void IRCDDBApp::Entry() if (NULL == getSendQ()) d->state = 10; // disconnect DB else { - printf( "IRCDDBApp: state=6 initialization completed\n"); + CLog::logInfo( "IRCDDBApp: state=6 initialization completed\n"); d->infoTimer = 2; d->initReady = true; d->state = 7; diff --git a/IRCDDBClient.cpp b/IRCDDBClient.cpp index c8b1c09..45d4ba1 100644 --- a/IRCDDBClient.cpp +++ b/IRCDDBClient.cpp @@ -23,6 +23,7 @@ along with this program. If not, see . #include "IRCClient.h" #include "IRCDDBApp.h" #include "Utils.h" +#include "Log.h" struct CIRCDDBClientPrivate { @@ -50,7 +51,7 @@ CIRCDDBClient::~CIRCDDBClient() // A false return implies a network error, or unable to log in bool CIRCDDBClient::open() { - printf("start client and app\n"); + CLog::logInfo("start client and app\n"); d->client->startWork(); d->app->startWork(); return true; @@ -87,27 +88,27 @@ bool CIRCDDBClient::sendHeard( const std::string& myCall, const std::string& myC const std::string& rpt2, unsigned char flag1, unsigned char flag2, unsigned char flag3 ) { if (myCall.size() != 8) { - printf("CIRCDDBClient::sendHeard:myCall='%s' len != 8\n", myCall.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeard:myCall='%s' len != 8\n", myCall.c_str()); return false; } if (myCallExt.size() != 4) { - printf("CIRCDDBClient::sendHeard:myCallExt='%s' len != 4\n", myCallExt.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeard:myCallExt='%s' len != 4\n", myCallExt.c_str()); return false; } if (yourCall.size() != 8) { - printf("CIRCDDBClient::sendHeard:yourCall='%s' len != 8\n", yourCall.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeard:yourCall='%s' len != 8\n", yourCall.c_str()); return false; } if (rpt1.size() != 8) { - printf("CIRCDDBClient::sendHeard:rpt1='%s' len != 8\n", rpt1.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeard:rpt1='%s' len != 8\n", rpt1.c_str()); return false; } if (rpt2.size() != 8) { - printf("CIRCDDBClient::sendHeard:rpt2='%s' len != 8\n", rpt2.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeard:rpt2='%s' len != 8\n", rpt2.c_str()); return false; } @@ -116,10 +117,10 @@ bool CIRCDDBClient::sendHeard( const std::string& myCall, const std::string& myC void CIRCDDBClient::sendDStarGatewayInfo(const std::string subcommand, const std::vector parms) { - printf("CIRCDDBClient::sendDStarGatewayInfo subcommand %s parms", subcommand.c_str()); + CLog::logInfo("CIRCDDBClient::sendDStarGatewayInfo subcommand %s parms", subcommand.c_str()); for(unsigned int i=0; i < parms.size();i++) - printf(" %s", parms[i].c_str()); - printf("\n"); + CLog::logInfo(" %s", parms[i].c_str()); + CLog::logInfo("\n"); if(m_isQuadNet) { d->app->sendDStarGatewayInfo(subcommand, parms); @@ -131,27 +132,27 @@ bool CIRCDDBClient::sendHeardWithTXMsg(const std::string& myCall, const std::str const std::string& rpt2, unsigned char flag1, unsigned char flag2, unsigned char flag3, const std::string& network_destination, const std::string& tx_message) { if (myCall.size() != 8) { - printf("CIRCDDBClient::sendHeardWithTXMsg:myCall='%s' len != 8\n", myCall.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXMsg:myCall='%s' len != 8\n", myCall.c_str()); return false; } if (myCallExt.size() != 4) { - printf("CIRCDDBClient::sendHeardWithTXMsg:myCallExt='%s' len != 4\n", myCallExt.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXMsg:myCallExt='%s' len != 4\n", myCallExt.c_str()); return false; } if (yourCall.size() != 8) { - printf("CIRCDDBClient::sendHeardWithTXMsg:yourCall='%s' len != 8\n", yourCall.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXMsg:yourCall='%s' len != 8\n", yourCall.c_str()); return false; } if (rpt1.size() != 8) { - printf("CIRCDDBClient::sendHeardWithTXMsg:rpt1='%s' len != 8\n", rpt1.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXMsg:rpt1='%s' len != 8\n", rpt1.c_str()); return false; } if (rpt2.size() != 8) { - printf("CIRCDDBClient::sendHeardWithTXMsg:rpt2='%s' len != 8\n", rpt2.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXMsg:rpt2='%s' len != 8\n", rpt2.c_str()); return false; } @@ -160,7 +161,7 @@ bool CIRCDDBClient::sendHeardWithTXMsg(const std::string& myCall, const std::str dest = std::string(" "); if (8 != dest.size()) { - printf("CIRCDDBClient::sendHeardWithTXMsg:network_destination='%s' len != 8\n", dest.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXMsg:network_destination='%s' len != 8\n", dest.c_str()); return false; } @@ -183,42 +184,42 @@ bool CIRCDDBClient::sendHeardWithTXStats( const std::string& myCall, const std:: const std::string& rpt2, unsigned char flag1, unsigned char flag2, unsigned char flag3, int num_dv_frames, int num_dv_silent_frames, int num_bit_errors) { if ((num_dv_frames <= 0) || (num_dv_frames > 65535)) { - printf("CIRCDDBClient::sendHeardWithTXStats:num_dv_frames=%d not in range 1-65535\n", num_dv_frames); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXStats:num_dv_frames=%d not in range 1-65535\n", num_dv_frames); return false; } if (num_dv_silent_frames > num_dv_frames) { - printf("CIRCDDBClient::sendHeardWithTXStats:num_dv_silent_frames=%d > num_dv_frames=%d\n", num_dv_silent_frames, num_dv_frames); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXStats:num_dv_silent_frames=%d > num_dv_frames=%d\n", num_dv_silent_frames, num_dv_frames); return false; } if (num_bit_errors > (4*num_dv_frames)) { // max 4 bit errors per frame - printf("CIRCDDBClient::sendHeardWithTXStats:num_bit_errors > (4*num_dv_frames), %d > 4*%d\n", num_bit_errors, num_dv_frames); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXStats:num_bit_errors > (4*num_dv_frames), %d > 4*%d\n", num_bit_errors, num_dv_frames); return false; } if (myCall.size() != 8) { - printf("CIRCDDBClient::sendHeardWithTXStats:myCall='%s' len != 8\n", myCall.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXStats:myCall='%s' len != 8\n", myCall.c_str()); return false; } if (myCallExt.size() != 4) { - printf("CIRCDDBClient::sendHeardWithTXStats:myCallExt='%s' len != 4\n", myCallExt.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXStats:myCallExt='%s' len != 4\n", myCallExt.c_str()); return false; } if (yourCall.size() != 8) { - printf("CIRCDDBClient::sendHeardWithTXStats:yourCall='%s' len != 8\n", yourCall.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXStats:yourCall='%s' len != 8\n", yourCall.c_str()); return false; } if (rpt1.size() != 8) { - printf("CIRCDDBClient::sendHeardWithTXStats:rpt1='%s' len != 8\n", rpt1.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXStats:rpt1='%s' len != 8\n", rpt1.c_str()); return false; } if (rpt2.size() != 8) { - printf("CIRCDDBClient::sendHeardWithTXStats:rpt2='%s' len != 8\n", rpt2.c_str()); + CLog::logInfo("CIRCDDBClient::sendHeardWithTXStats:rpt2='%s' len != 8\n", rpt2.c_str()); return false; } @@ -244,7 +245,7 @@ bool CIRCDDBClient::sendHeardWithTXStats( const std::string& myCall, const std:: bool CIRCDDBClient::findGateway(const std::string& gatewayCallsign) { if (8 != gatewayCallsign.size()) { - printf("CIRCDDBClient::findGateway:gatewayCallsign='%s' len != 8\n", gatewayCallsign.c_str()); + CLog::logInfo("CIRCDDBClient::findGateway:gatewayCallsign='%s' len != 8\n", gatewayCallsign.c_str()); return false; } std::string gw(gatewayCallsign); @@ -256,7 +257,7 @@ bool CIRCDDBClient::findGateway(const std::string& gatewayCallsign) bool CIRCDDBClient::findRepeater(const std::string& repeaterCallsign) { if (8 != repeaterCallsign.size()) { - printf("CIRCDDBClient::findRepeater:repeaterCallsign='%s' len != 8\n", repeaterCallsign.c_str()); + CLog::logInfo("CIRCDDBClient::findRepeater:repeaterCallsign='%s' len != 8\n", repeaterCallsign.c_str()); return false; } std::string rptr(repeaterCallsign); @@ -268,7 +269,7 @@ bool CIRCDDBClient::findRepeater(const std::string& repeaterCallsign) bool CIRCDDBClient::findUser(const std::string& userCallsign) { if (8 != userCallsign.size()) { - printf("CIRCDDBClient::findUser:userCall='%s' len != 8\n", userCallsign.c_str()); + CLog::logInfo("CIRCDDBClient::findUser:userCall='%s' len != 8\n", userCallsign.c_str()); return false; } std::string usr(userCallsign); @@ -291,24 +292,24 @@ bool CIRCDDBClient::receiveRepeater(std::string& repeaterCallsign, std::string& IRCDDB_RESPONSE_TYPE rt = d->app->getReplyMessageType(); if (rt != IDRT_REPEATER) { - printf("CIRCDDBClient::receiveRepeater: unexpected response type=%d\n", rt); + CLog::logInfo("CIRCDDBClient::receiveRepeater: unexpected response type=%d\n", rt); return false; } IRCMessage *m = d->app->getReplyMessage(); if (m == NULL) { - printf("CIRCDDBClient::receiveRepeater: no message\n"); + CLog::logInfo("CIRCDDBClient::receiveRepeater: no message\n"); return false; } if (m->getCommand().compare("IDRT_REPEATER")) { - printf("CIRCDDBClient::receiveRepeater: wrong message type, expected 'IDRT_REPEATER, got '%s'\n", m->getCommand().c_str()); + CLog::logInfo("CIRCDDBClient::receiveRepeater: wrong message type, expected 'IDRT_REPEATER, got '%s'\n", m->getCommand().c_str()); delete m; return false; } if (3 != m->getParamCount()) { - printf("CIRCDDBClient::receiveRepeater: unexpected number of message parameters, expected 3, got %d\n", m->getParamCount()); + CLog::logInfo("CIRCDDBClient::receiveRepeater: unexpected number of message parameters, expected 3, got %d\n", m->getParamCount()); delete m; return false; } @@ -327,25 +328,25 @@ bool CIRCDDBClient::receiveGateway(std::string& gatewayCallsign, std::string& ad IRCDDB_RESPONSE_TYPE rt = d->app->getReplyMessageType(); if (rt != IDRT_GATEWAY) { - printf("CIRCDDBClient::receiveGateway: unexpected response type=%d\n", rt); + CLog::logInfo("CIRCDDBClient::receiveGateway: unexpected response type=%d\n", rt); return false; } IRCMessage *m = d->app->getReplyMessage(); if (m == NULL) { - printf("CIRCDDBClient::receiveGateway: no message\n"); + CLog::logInfo("CIRCDDBClient::receiveGateway: no message\n"); return false; } if (m->getCommand().compare("IDRT_GATEWAY")) { - printf("CIRCDDBClient::receiveGateway: wrong message type, expected 'IDRT_GATEWAY' got '%s'\n", m->getCommand().c_str()); + CLog::logInfo("CIRCDDBClient::receiveGateway: wrong message type, expected 'IDRT_GATEWAY' got '%s'\n", m->getCommand().c_str()); delete m; return false; } if (2 != m->getParamCount()) { - printf("CIRCDDBClient::receiveGateway: unexpected number of message parameters, expected 2, got %d\n", m->getParamCount()); + CLog::logInfo("CIRCDDBClient::receiveGateway: unexpected number of message parameters, expected 2, got %d\n", m->getParamCount()); delete m; return false; } @@ -369,25 +370,25 @@ bool CIRCDDBClient::receiveUser(std::string& userCallsign, std::string& repeater IRCDDB_RESPONSE_TYPE rt = d->app->getReplyMessageType(); if (rt != IDRT_USER) { - printf("CIRCDDBClient::receiveUser: unexpected response type=%d\n", rt); + CLog::logInfo("CIRCDDBClient::receiveUser: unexpected response type=%d\n", rt); return false; } IRCMessage * m = d->app->getReplyMessage(); if (m == NULL) { - printf("CIRCDDBClient::receiveUser: no message\n"); + CLog::logInfo("CIRCDDBClient::receiveUser: no message\n"); return false; } if (m->getCommand().compare("IDRT_USER")) { - printf("CIRCDDBClient::receiveUser: wrong message type, expected 'IDRT_USER', got '%s'\n", m->getCommand().c_str()); + CLog::logInfo("CIRCDDBClient::receiveUser: wrong message type, expected 'IDRT_USER', got '%s'\n", m->getCommand().c_str()); delete m; return false; } if (5 != m->getParamCount()) { - printf("CIRCDDBClient::receiveUser: unexpected number of message parameters, expected 5, got %d\n", m->getParamCount()); + CLog::logInfo("CIRCDDBClient::receiveUser: unexpected number of message parameters, expected 5, got %d\n", m->getParamCount()); delete m; return false; } diff --git a/IRCDDBMultiClient.cpp b/IRCDDBMultiClient.cpp index 39e23a2..fc4bc98 100644 --- a/IRCDDBMultiClient.cpp +++ b/IRCDDBMultiClient.cpp @@ -20,9 +20,12 @@ along with this program. If not, see . */ -#include "IRCDDBMultiClient.h" + #include +#include "IRCDDBMultiClient.h" +#include "Log.h" + CIRCDDBMultiClient::CIRCDDBMultiClient(const CIRCDDB_Array& clients) : m_clients(), m_queriesLock(), @@ -284,11 +287,11 @@ bool CIRCDDBMultiClient::receiveUser(std::string & userCallsign, std::string & r { CIRCDDBMultiClientQuery * item = checkAndGetNextResponse(IDRT_USER, "CIRCDDBMultiClient::receiveUser: unexpected response type"); if (item == NULL) { - //wxLogMessage(wxT("CIRCDDBMultiClient::receiveUser NO USER IN QUEUE")); + //CLog::logInfo(wxT("CIRCDDBMultiClient::receiveUser NO USER IN QUEUE")); return false; } - //wxLogMessage(wxT("CIRCDDBMultiClient::receiveUser : %s"), item->toString()); + //CLog::logInfo(wxT("CIRCDDBMultiClient::receiveUser : %s"), item->toString()); userCallsign = item->getUser(); repeaterCallsign = item->getRepeater(); @@ -312,7 +315,7 @@ CIRCDDBMultiClientQuery * CIRCDDBMultiClient::checkAndGetNextResponse(IRCDDB_RES m_responseQueueLock.lock(); if (m_responseQueue.size() == 0 || m_responseQueue[0]->getType() != expectedType) { - printf(errorMessage.c_str()); + CLog::logInfo(errorMessage.c_str()); } else { item = m_responseQueue[0]; diff --git a/IRCProtocol.cpp b/IRCProtocol.cpp index 5a5b7c6..2390404 100644 --- a/IRCProtocol.cpp +++ b/IRCProtocol.cpp @@ -22,6 +22,8 @@ along with this program. If not, see . #include "IRCProtocol.h" #include "Utils.h" +#include "IRCDDBMultiClient.h" +#include "Log.h" #define CIRCDDB_VERSION "2.0.0" @@ -74,7 +76,7 @@ void IRCProtocol::setNetworkReady(bool b) { if (b == true) { if (0 != m_state) - printf("IRCProtocol::setNetworkReady: unexpected state\n"); + CLog::logInfo("IRCProtocol::setNetworkReady: unexpected state\n"); m_state = 1; chooseNewNick(); } else diff --git a/IRCReceiver.cpp b/IRCReceiver.cpp index c968495..ca25604 100644 --- a/IRCReceiver.cpp +++ b/IRCReceiver.cpp @@ -23,6 +23,7 @@ along with this program. If not, see . #include "IRCReceiver.h" #include "Utils.h" +#include "Log.h" IRCReceiver::IRCReceiver(int sock, IRCMessageQueue *q) { @@ -62,21 +63,21 @@ static int doRead(int sock, char *buf, int buf_size) int res = select(sock+1, &rdset, NULL, &errset, &tv); if (res < 0) { - printf("IRCReceiver::doRead: select\n"); + CLog::logInfo("IRCReceiver::doRead: select\n"); return -1; } else if (res > 0) { if (FD_ISSET(sock, &errset)) { - printf("IRCReceiver::doRead: select (FD_ISSET(sock, exceptfds))\n"); + CLog::logInfo("IRCReceiver::doRead: select (FD_ISSET(sock, exceptfds))\n"); return -1; } if (FD_ISSET(sock, &rdset)) { res = recv(sock, buf, buf_size, 0); if (res < 0) { - printf("IRCReceiver::doRead: read\n"); + CLog::logInfo("IRCReceiver::doRead: read\n"); return -1; } else if (res == 0) { - printf("IRCReceiver::doRead: EOF read==0\n"); + CLog::logInfo("IRCReceiver::doRead: EOF read==0\n"); return -1; } else return res; diff --git a/IcomRepeaterProtocolHandler.cpp b/IcomRepeaterProtocolHandler.cpp index b37a913..d220690 100644 --- a/IcomRepeaterProtocolHandler.cpp +++ b/IcomRepeaterProtocolHandler.cpp @@ -112,7 +112,7 @@ bool CIcomRepeaterProtocolHandler::open() if (length == 10 && m_buffer[0U] == 'I' && m_buffer[1U] == 'N' && m_buffer[2U] == 'I' && m_buffer[3U] == 'T' && m_buffer[6U] == 0x72 && m_buffer[7U] == 0x00) { m_seqNo = m_buffer[4U] * 256U + m_buffer[5U] + 1U; - wxLogMessage("Initial sequence number from the RP2C is %u", m_seqNo); + CLog::logInfo("Initial sequence number from the RP2C is %u", m_seqNo); // Start the thread Create(); @@ -126,14 +126,14 @@ bool CIcomRepeaterProtocolHandler::open() m_socket.close(); - wxLogError("No reply from the RP2C for 10 seconds, aborting"); + CLog::logError("No reply from the RP2C for 10 seconds, aborting"); return false; } void* CIcomRepeaterProtocolHandler::Entry() { - wxLogMessage("Starting the Icom Controller thread"); + CLog::logInfo("Starting the Icom Controller thread"); try { while (!m_killed) { @@ -148,13 +148,13 @@ void* CIcomRepeaterProtocolHandler::Entry() } catch (std::exception& e) { std::string message(e.what()); - wxLogError("Exception raised in the Icom Controller thread - \"%s\"", message.c_str()); + CLog::logError("Exception raised in the Icom Controller thread - \"%s\"", message.c_str()); } catch (...) { - wxLogError("Unknown exception raised in the Icom Controller thread"); + CLog::logError("Unknown exception raised in the Icom Controller thread"); } - wxLogMessage("Stopping the Icom Controller thread"); + CLog::logInfo("Stopping the Icom Controller thread"); m_socket.close(); @@ -209,7 +209,7 @@ void CIcomRepeaterProtocolHandler::readIcomPackets() return; if (address.s_addr != m_icomAddress.s_addr || port != m_icomPort) { - wxLogError("Incoming Icom data from an unknown source"); + CLog::logError("Incoming Icom data from an unknown source"); continue; } @@ -247,7 +247,7 @@ void CIcomRepeaterProtocolHandler::readIcomPackets() CHeardData* heard = new CHeardData; bool ret = heard->setIcomRepeaterData(m_buffer, length, m_icomAddress, m_icomPort); if (!ret) { - wxLogError("Invalid heard data from the RP2C"); + CLog::logError("Invalid heard data from the RP2C"); delete heard; continue; } @@ -267,7 +267,7 @@ void CIcomRepeaterProtocolHandler::readIcomPackets() CDDData* data = new CDDData; bool ret = data->setIcomRepeaterData(m_buffer, length, m_icomAddress, m_icomPort); if (!ret) { - wxLogError("Invalid DD data from the RP2C"); + CLog::logError("Invalid DD data from the RP2C"); delete data; continue; } @@ -282,7 +282,7 @@ void CIcomRepeaterProtocolHandler::readIcomPackets() CHeaderData* header = new CHeaderData; bool ret = header->setIcomRepeaterData(m_buffer, length, true, m_icomAddress, m_icomPort); if (!ret) { - wxLogError("Invalid header data or checksum from the RP2C"); + CLog::logError("Invalid header data or checksum from the RP2C"); delete header; continue; } @@ -298,7 +298,7 @@ void CIcomRepeaterProtocolHandler::readIcomPackets() CAMBEData* data = new CAMBEData; bool ret = data->setIcomRepeaterData(m_buffer, length, m_icomAddress, m_icomPort); if (!ret) { - wxLogError("Invalid AMBE data from the RP2C"); + CLog::logError("Invalid AMBE data from the RP2C"); delete data; continue; } @@ -325,7 +325,7 @@ void CIcomRepeaterProtocolHandler::sendGwyPackets() if (m_ackQueue == NULL) { m_ackQueue = m_gwyQueue.getData(); if (m_ackQueue == NULL) { - wxLogError("getData of a non-empty gateway queue is NULL"); + CLog::logError("getData of a non-empty gateway queue is NULL"); return; } } @@ -355,7 +355,7 @@ void CIcomRepeaterProtocolHandler::sendGwyPackets() break; default: - wxLogError("Invalid type in the gateway queue"); + CLog::logError("Invalid type in the gateway queue"); break; } @@ -366,7 +366,7 @@ void CIcomRepeaterProtocolHandler::sendGwyPackets() m_retryTimer.start(); if (m_tries > 0U && (m_tries % 100U) == 0U) - wxLogMessage("No reply from the RP2C after %u retries", m_tries); + CLog::logInfo("No reply from the RP2C after %u retries", m_tries); } } @@ -377,7 +377,7 @@ REPEATER_TYPE CIcomRepeaterProtocolHandler::read() } else { CDataQueue* dq = m_rptrQueue.peek(); if (dq == NULL) { - wxLogError("Peek of a non-empty repeater queue is NULL"); + CLog::logError("Peek of a non-empty repeater queue is NULL"); m_type = RT_NONE; } else { m_type = dq->getType(); @@ -394,12 +394,12 @@ CPollData* CIcomRepeaterProtocolHandler::readPoll() CDataQueue* dq = m_rptrQueue.getData(); if (dq == NULL) { - wxLogError("Missing DataQueue in readPoll"); + CLog::logError("Missing DataQueue in readPoll"); return NULL; } if (dq->getType() != RT_POLL) { - wxLogError("Wrong DataQueue type in readPoll"); + CLog::logError("Wrong DataQueue type in readPoll"); delete dq; return NULL; } @@ -419,12 +419,12 @@ CHeaderData* CIcomRepeaterProtocolHandler::readHeader() CDataQueue* dq = m_rptrQueue.getData(); if (dq == NULL) { - wxLogError("Missing DataQueue in readHeader"); + CLog::logError("Missing DataQueue in readHeader"); return NULL; } if (dq->getType() != RT_HEADER) { - wxLogError("Wrong DataQueue type in readHeader"); + CLog::logError("Wrong DataQueue type in readHeader"); delete dq; return NULL; } @@ -443,12 +443,12 @@ CAMBEData* CIcomRepeaterProtocolHandler::readAMBE() CDataQueue* dq = m_rptrQueue.getData(); if (dq == NULL) { - wxLogError("Missing DataQueue in readData"); + CLog::logError("Missing DataQueue in readData"); return NULL; } if (dq->getType() != RT_AMBE) { - wxLogError("Wrong DataQueue type in readData"); + CLog::logError("Wrong DataQueue type in readData"); delete dq; return NULL; } @@ -467,12 +467,12 @@ CHeardData* CIcomRepeaterProtocolHandler::readHeard() CDataQueue* dq = m_rptrQueue.getData(); if (dq == NULL) { - wxLogError("Missing DataQueue in readHeard"); + CLog::logError("Missing DataQueue in readHeard"); return NULL; } if (dq->getType() != RT_HEARD) { - wxLogError("Wrong DataQueue type in readHeard"); + CLog::logError("Wrong DataQueue type in readHeard"); delete dq; return NULL; } @@ -491,12 +491,12 @@ CDDData* CIcomRepeaterProtocolHandler::readDD() CDataQueue* dq = m_rptrQueue.getData(); if (dq == NULL) { - wxLogError("Missing DataQueue in readData"); + CLog::logError("Missing DataQueue in readData"); return NULL; } if (dq->getType() != RT_DD) { - wxLogError("Wrong DataQueue type in readData"); + CLog::logError("Wrong DataQueue type in readData"); delete dq; return NULL; } diff --git a/Log.cpp b/Log.cpp new file mode 100644 index 0000000..c0404fb --- /dev/null +++ b/Log.cpp @@ -0,0 +1,42 @@ + +/* + * Copyright (c) 2021 by Geoffrey Merck F4FXL / KC3FRA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include "Log.h" + +LOG_SEVERITY CLog::m_level = LS_INFO; +std::string CLog::m_file = ""; +bool CLog::m_logToConsole = true; + +void CLog::initialize(const std::string& logfile, LOG_SEVERITY logLevel, bool logToConsole) +{ + m_file = logfile; + m_level = logLevel; + m_logToConsole = logToConsole; +} + +void CLog::getTimeStamp(std::string & s) +{ + std::time_t now= std::time(0); + std::tm* now_tm= std::gmtime(&now); + char buf[64]; + std::strftime(buf, 42, "%Y-%m-%d %T", now_tm); + s = std::string(buf); +} \ No newline at end of file diff --git a/Log.h b/Log.h index f8e3283..0e99426 100644 --- a/Log.h +++ b/Log.h @@ -16,13 +16,109 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* - * A Dummy wxLog replacement to speed up conversion - */ #pragma once -#define wxLogMessage(...) ::printf(__VA_ARGS__) -#define wxLogError(...) ::printf(__VA_ARGS__) -#define wxLogWarning(...) ::printf(__VA_ARGS__) -#define wxLogInfo(...) ::printf(__VA_ARGS__) \ No newline at end of file +#include +#include +#include +#include +#include +#include + +#include "StringUtils.h" + +enum LOG_SEVERITY { + LS_TRACE = 1, + LS_DEBUG, + LS_INFO, + LS_WARNING, + LS_ERROR, + LS_FATAL +}; + +class CLog +{ +private: + static LOG_SEVERITY m_level; + static std::string m_file; + static bool m_logToConsole; + + static void getTimeStamp(std::string & s); + +public: + + static void initialize(const std::string& logfile, LOG_SEVERITY logLevel, bool logToConsole); + + template static void logDebug(const std::string & f, Args... args) + { + log(LS_DEBUG, f, args...); + } + + template static void logInfo(const std::string & f, Args... args) + { + log(LS_INFO, f, args...); + } + + template static void logWarning(const std::string & f, Args... args) + { + log(LS_WARNING, f, args...); + } + + template static void logError(const std::string & f, Args... args) + { + log(LS_ERROR, f, args...); + } + + template static void logFatal(const std::string & f, Args... args) + { + log(LS_FATAL, f, args...); + } + + template static void log(LOG_SEVERITY severity, const std::string & f, Args... args) + { + if(severity >= CLog::m_level || CLog::m_file.empty()) { + std::string severityStr; + switch (severity) + { + case LS_DEBUG: + severityStr = "DEBUG "; + break; + case LS_ERROR: + severityStr = "ERROR "; + break; + case LS_FATAL: + severityStr = "FATAL "; + break; + case LS_INFO : + severityStr = "INFO "; + break; + case LS_WARNING: + severityStr = "WARNING"; + break; + case LS_TRACE: + severityStr = "TRACE "; + break; + default: + break; + } + + std::string message = CStringUtils::string_format(f, args...); + boost::trim(message); + std::string timeUtc; + getTimeStamp(timeUtc); + std::stringstream s; + s << "[" << timeUtc << "] [" << severityStr << "] " << message << std::endl; + + if(CLog::m_logToConsole || CLog::m_file.empty()) + std::cout << s.str(); + + std::ofstream file; + file.open(CLog::m_file, std::ios::app); + if(file.is_open()) { + file << s.str(); + file.close(); + } + } + } +}; diff --git a/RemoteHandler.cpp b/RemoteHandler.cpp index 3cfa1a9..d4f4df2 100644 --- a/RemoteHandler.cpp +++ b/RemoteHandler.cpp @@ -55,7 +55,7 @@ void CRemoteHandler::process() switch (type) { case RPHT_LOGOUT: m_handler.setLoggedIn(false); - wxLogMessage("Remote control user has logged out"); + CLog::logInfo("Remote control user has logged out"); break; case RPHT_LOGIN: m_random = ::rand(); @@ -64,11 +64,11 @@ void CRemoteHandler::process() case RPHT_HASH: { bool valid = m_handler.readHash(m_password, m_random); if (valid) { - wxLogMessage("Remote control user has logged in"); + CLog::logInfo("Remote control user has logged in"); m_handler.setLoggedIn(true); m_handler.sendACK(); } else { - wxLogMessage("Remote control user has failed login authentication"); + CLog::logInfo("Remote control user has failed login authentication"); m_handler.setLoggedIn(false); m_handler.sendNAK("Invalid password"); } @@ -94,9 +94,9 @@ void CRemoteHandler::process() RECONNECT reconnect; m_handler.readLink(callsign, reconnect, reflector); if (reflector.empty()) - wxLogMessage("Remote control user has linked \"%s\" to \"None\" with reconnect %d", callsign.c_str(), int(reconnect)); + CLog::logInfo("Remote control user has linked \"%s\" to \"None\" with reconnect %d", callsign.c_str(), int(reconnect)); else - wxLogMessage("Remote control user has linked \"%s\" to \"%s\" with reconnect %d", callsign.c_str(), reflector.c_str(), int(reconnect)); + CLog::logInfo("Remote control user has linked \"%s\" to \"%s\" with reconnect %d", callsign.c_str(), reflector.c_str(), int(reconnect)); link(callsign, reconnect, reflector, true); } break; @@ -104,7 +104,7 @@ void CRemoteHandler::process() std::string callsign, reflector; PROTOCOL protocol; m_handler.readUnlink(callsign, protocol, reflector); - wxLogMessage("Remote control user has unlinked \"%s\" from \"%s\" for protocol %d", callsign.c_str(), reflector.c_str(), int(protocol)); + CLog::logInfo("Remote control user has unlinked \"%s\" from \"%s\" for protocol %d", callsign.c_str(), reflector.c_str(), int(protocol)); unlink(callsign, protocol, reflector); } break; @@ -113,9 +113,9 @@ void CRemoteHandler::process() RECONNECT reconnect; m_handler.readLinkScr(callsign, reconnect, reflector); if (reflector.empty()) - wxLogMessage("Remote control user has linked \"%s\" to \"None\" with reconnect %d from localhost", callsign.c_str(), reconnect); + CLog::logInfo("Remote control user has linked \"%s\" to \"None\" with reconnect %d from localhost", callsign.c_str(), reconnect); else - wxLogMessage("Remote control user has linked \"%s\" to \"%s\" with reconnect %d from localhost", callsign.c_str(), reflector.c_str(), reconnect); + CLog::logInfo("Remote control user has linked \"%s\" to \"%s\" with reconnect %d from localhost", callsign.c_str(), reflector.c_str(), reconnect); link(callsign, reconnect, reflector, false); } break; @@ -123,7 +123,7 @@ void CRemoteHandler::process() case RPHT_LOGOFF: { std::string callsign, user; m_handler.readLogoff(callsign, user); - wxLogMessage("Remote control user has logged off \"%s\" from \"%s\"", user.c_str(), callsign.c_str()); + CLog::logInfo("Remote control user has logged off \"%s\" from \"%s\"", user.c_str(), callsign.c_str()); logoff(callsign, user); } break; diff --git a/RepeaterHandler.cpp b/RepeaterHandler.cpp index 481d208..1670c6c 100644 --- a/RepeaterHandler.cpp +++ b/RepeaterHandler.cpp @@ -295,7 +295,7 @@ void CRepeaterHandler::add(const std::string& callsign, const std::string& band, } } - wxLogError("Cannot add repeater with callsign %s, no space", callsign.c_str()); + CLog::logError("Cannot add repeater with callsign %s, no space", callsign.c_str()); delete repeater; } @@ -589,12 +589,12 @@ void CRepeaterHandler::processRepeater(CHeaderData& header) m_band1 = band1; m_band2 = band2; m_band3 = band3; - wxLogMessage("Repeater %s registered with bands %u %u %u", m_rptCall1.c_str(), m_band1, m_band2, m_band3); + CLog::logInfo("Repeater %s registered with bands %u %u %u", m_rptCall1.c_str(), m_band1, m_band2, m_band3); } } if (m_flag1 == 0x01) { - wxLogMessage("Received a busy message from repeater %s", m_rptCall1.c_str()); + CLog::logInfo("Received a busy message from repeater %s", m_rptCall1.c_str()); return; } @@ -690,13 +690,13 @@ void CRepeaterHandler::processRepeater(CHeaderData& header) if (m_rptCall2 != (m_gwyCallsign) && m_rptCall2 != m_gateway) { CRepeaterHandler* repeater = findDVRepeater(m_rptCall2); if (repeater != NULL) { - wxLogMessage("Cross-band routing by %s from %s to %s", m_myCall1.c_str(), m_rptCallsign.c_str(), m_rptCall2.c_str()); + CLog::logInfo("Cross-band routing by %s from %s to %s", m_myCall1.c_str(), m_rptCallsign.c_str(), m_rptCall2.c_str()); m_xBandRptr = repeater; m_xBandRptr->process(header, DIR_INCOMING, AS_XBAND); m_g2Status = G2_XBAND; } else { // Keep the transmission local - wxLogMessage("Invalid cross-band route by %s from %s to %s", m_myCall1.c_str(), m_rptCallsign.c_str(), m_rptCall2.c_str()); + CLog::logInfo("Invalid cross-band route by %s from %s to %s", m_myCall1.c_str(), m_rptCallsign.c_str(), m_rptCall2.c_str()); m_g2Status = G2_LOCAL; } return; @@ -705,7 +705,7 @@ void CRepeaterHandler::processRepeater(CHeaderData& header) #ifdef USE_STARNET m_starNet = CStarNetHandler::findStarNet(header); if (m_starNet != NULL && !m_restricted) { - wxLogMessage(wxT("StarNet routing by %s to %s"), m_myCall1.c_str(), m_yourCall.c_str()); + CLog::logInfo(wxT("StarNet routing by %s to %s"), m_myCall1.c_str(), m_yourCall.c_str()); m_starNet->process(header); m_g2Status = G2_STARNET; return; @@ -992,12 +992,12 @@ void CRepeaterHandler::processBusy(CHeaderData& header) m_band1 = band1; m_band2 = band2; m_band3 = band3; - wxLogMessage("Repeater %s registered with bands %u %u %u", rptCall1.c_str(), m_band1, m_band2, m_band3); + CLog::logInfo("Repeater %s registered with bands %u %u %u", rptCall1.c_str(), m_band1, m_band2, m_band3); } } if (header.getFlag1() == 0x01) { - wxLogMessage("Received a busy message from repeater %s", rptCall1.c_str()); + CLog::logInfo("Received a busy message from repeater %s", rptCall1.c_str()); return; } @@ -1139,7 +1139,7 @@ void CRepeaterHandler::processRepeater(CDDData& data) if (m_ddCallsign.empty()) { m_ddCallsign = data.getYourCall(); - wxLogMessage("Added DD callsign %s", m_ddCallsign.c_str()); + CLog::logInfo("Added DD callsign %s", m_ddCallsign.c_str()); } CDDHandler::process(data); @@ -1345,7 +1345,7 @@ void CRepeaterHandler::resolveRepeaterInt(const std::string& repeater, const std CDPlusHandler::link(this, m_rptCallsign, m_linkRepeater, addr); m_linkStatus = LS_LINKING_DPLUS; } else { - wxLogMessage("Require D-Plus for linking to %s, but D-Plus is disabled", repeater.c_str()); + CLog::logInfo("Require D-Plus for linking to %s, but D-Plus is disabled", repeater.c_str()); m_linkStatus = LS_NONE; m_linkRepeater.clear(); m_linkGateway.clear(); @@ -1361,7 +1361,7 @@ void CRepeaterHandler::resolveRepeaterInt(const std::string& repeater, const std CDCSHandler::link(this, m_rptCallsign, m_linkRepeater, addr); m_linkStatus = LS_LINKING_DCS; } else { - wxLogMessage("Require DCS for linking to %s, but DCS is disabled", repeater.c_str()); + CLog::logInfo("Require DCS for linking to %s, but DCS is disabled", repeater.c_str()); m_linkStatus = LS_NONE; m_linkRepeater.clear(); m_linkGateway.clear(); @@ -1384,7 +1384,7 @@ void CRepeaterHandler::resolveRepeaterInt(const std::string& repeater, const std CDExtraHandler::link(this, m_rptCallsign, m_linkRepeater, addr); m_linkStatus = LS_LINKING_DEXTRA; } else { - wxLogMessage("Require DExtra for linking to %s, but DExtra is disabled", repeater.c_str()); + CLog::logInfo("Require DExtra for linking to %s, but DExtra is disabled", repeater.c_str()); m_linkStatus = LS_NONE; m_linkRepeater.clear(); m_linkGateway.clear(); @@ -1426,7 +1426,7 @@ void CRepeaterHandler::clockInt(unsigned int ms) if (m_linkReconnectTimer.isRunning() && m_linkReconnectTimer.hasExpired()) { if (m_linkStatus != LS_NONE && (m_linkStartup.empty() || m_linkStartup == " ")) { // Unlink if linked to something - wxLogMessage("Reconnect timer has expired, unlinking %s from %s", m_rptCallsign.c_str(), m_linkRepeater.c_str()); + CLog::logInfo("Reconnect timer has expired, unlinking %s from %s", m_rptCallsign.c_str(), m_linkRepeater.c_str()); CDExtraHandler::unlink(this); CDPlusHandler::unlink(this); @@ -1441,7 +1441,7 @@ void CRepeaterHandler::clockInt(unsigned int ms) } else if ((m_linkStatus == LS_NONE && !m_linkStartup.empty() && m_linkStartup != " ") || (m_linkStatus != LS_NONE && m_linkRepeater != m_linkStartup)) { // Relink if not linked or linked to the wrong reflector - wxLogMessage("Reconnect timer has expired, relinking %s to %s", m_rptCallsign.c_str(), m_linkStartup.c_str()); + CLog::logInfo("Reconnect timer has expired, relinking %s to %s", m_rptCallsign.c_str(), m_linkStartup.c_str()); // Check for just a change of letter if (m_linkStatus != LS_NONE) { @@ -1522,7 +1522,7 @@ void CRepeaterHandler::clockInt(unsigned int ms) if (m_g2Status == G2_USER || m_g2Status == G2_REPEATER) { // User or repeater not found in time, remove G2 settings - wxLogMessage("ircDDB did not reply within five seconds"); + CLog::logInfo("ircDDB did not reply within five seconds"); m_g2Status = G2_LOCAL; m_g2User.clear(); @@ -1533,7 +1533,7 @@ void CRepeaterHandler::clockInt(unsigned int ms) m_g2Header = NULL; } else if (m_linkStatus == LS_PENDING_IRCDDB) { // Repeater not found in time - wxLogMessage("ircDDB did not reply within five seconds"); + CLog::logInfo("ircDDB did not reply within five seconds"); m_linkStatus = LS_NONE; m_linkRepeater.clear(); @@ -1545,7 +1545,7 @@ void CRepeaterHandler::clockInt(unsigned int ms) #ifdef USE_CCS else if (m_linkStatus == LS_LINKING_CCS) { // CCS didn't reply in time - wxLogMessage(wxT("CCS did not reply within five seconds")); + CLog::logInfo(wxT("CCS did not reply within five seconds")); m_ccsHandler->stopLink(); @@ -1565,7 +1565,7 @@ void CRepeaterHandler::clockInt(unsigned int ms) // If the watchdog timer has expired, clean up if (m_watchdogTimer.isRunning() && m_watchdogTimer.hasExpired()) { - wxLogMessage("Radio watchdog timer for %s has expired", m_rptCallsign.c_str()); + CLog::logInfo("Radio watchdog timer for %s has expired", m_rptCallsign.c_str()); m_watchdogTimer.stop(); if (m_repeaterId != 0x00U) { @@ -1657,28 +1657,28 @@ void CRepeaterHandler::clockInt(unsigned int ms) void CRepeaterHandler::linkUp(DSTAR_PROTOCOL protocol, const std::string& callsign) { if (protocol == DP_DEXTRA && m_linkStatus == LS_LINKING_DEXTRA) { - wxLogMessage("DExtra link to %s established", callsign.c_str()); + CLog::logInfo("DExtra link to %s established", callsign.c_str()); m_linkStatus = LS_LINKED_DEXTRA; writeLinkedTo(callsign); triggerInfo(); } if (protocol == DP_DPLUS && m_linkStatus == LS_LINKING_DPLUS) { - wxLogMessage("D-Plus link to %s established", callsign.c_str()); + CLog::logInfo("D-Plus link to %s established", callsign.c_str()); m_linkStatus = LS_LINKED_DPLUS; writeLinkedTo(callsign); triggerInfo(); } if (protocol == DP_DCS && m_linkStatus == LS_LINKING_DCS) { - wxLogMessage("DCS link to %s established", callsign.c_str()); + CLog::logInfo("DCS link to %s established", callsign.c_str()); m_linkStatus = LS_LINKED_DCS; writeLinkedTo(callsign); triggerInfo(); } if (protocol == DP_DCS && m_linkStatus == LS_LINKING_LOOPBACK) { - wxLogMessage("Loopback link to %s established", callsign.c_str()); + CLog::logInfo("Loopback link to %s established", callsign.c_str()); m_linkStatus = LS_LINKED_LOOPBACK; writeLinkedTo(callsign); triggerInfo(); @@ -1690,7 +1690,7 @@ bool CRepeaterHandler::linkFailed(DSTAR_PROTOCOL protocol, const std::string& ca // Is relink to another module required? if (!isRecoverable && m_linkRelink) { m_linkRelink = false; - wxLogMessage("Relinking %s from %s to %s", m_rptCallsign.c_str(), callsign.c_str(), m_linkRepeater.c_str()); + CLog::logInfo("Relinking %s from %s to %s", m_rptCallsign.c_str(), callsign.c_str(), m_linkRepeater.c_str()); linkInt(m_linkRepeater); return false; } @@ -1699,13 +1699,13 @@ bool CRepeaterHandler::linkFailed(DSTAR_PROTOCOL protocol, const std::string& ca if (m_linkStatus == LS_NONE || m_linkRepeater != callsign) { switch (protocol) { case DP_DCS: - wxLogMessage("DCS link to %s has failed", callsign.c_str()); + CLog::logInfo("DCS link to %s has failed", callsign.c_str()); break; case DP_DEXTRA: - wxLogMessage("DExtra link to %s has failed", callsign.c_str()); + CLog::logInfo("DExtra link to %s has failed", callsign.c_str()); break; case DP_DPLUS: - wxLogMessage("D-Plus link to %s has failed", callsign.c_str()); + CLog::logInfo("D-Plus link to %s has failed", callsign.c_str()); break; default: break; @@ -1716,7 +1716,7 @@ bool CRepeaterHandler::linkFailed(DSTAR_PROTOCOL protocol, const std::string& ca if (!isRecoverable) { if (protocol == DP_DEXTRA && callsign == m_linkRepeater) { - wxLogMessage("DExtra link to %s has failed", m_linkRepeater.c_str()); + CLog::logInfo("DExtra link to %s has failed", m_linkRepeater.c_str()); m_linkRepeater.clear(); m_linkStatus = LS_NONE; writeNotLinked(); @@ -1724,7 +1724,7 @@ bool CRepeaterHandler::linkFailed(DSTAR_PROTOCOL protocol, const std::string& ca } if (protocol == DP_DPLUS && callsign == m_linkRepeater) { - wxLogMessage("D-Plus link to %s has failed", m_linkRepeater.c_str()); + CLog::logInfo("D-Plus link to %s has failed", m_linkRepeater.c_str()); m_linkRepeater.clear(); m_linkStatus = LS_NONE; writeNotLinked(); @@ -1733,9 +1733,9 @@ bool CRepeaterHandler::linkFailed(DSTAR_PROTOCOL protocol, const std::string& ca if (protocol == DP_DCS && callsign == m_linkRepeater) { if (m_linkStatus == LS_LINKED_DCS || m_linkStatus == LS_LINKING_DCS) - wxLogMessage("DCS link to %s has failed", m_linkRepeater.c_str()); + CLog::logInfo("DCS link to %s has failed", m_linkRepeater.c_str()); else - wxLogMessage("Loopback link to %s has failed", m_linkRepeater.c_str()); + CLog::logInfo("Loopback link to %s has failed", m_linkRepeater.c_str()); m_linkRepeater.clear(); m_linkStatus = LS_NONE; writeNotLinked(); @@ -1748,7 +1748,7 @@ bool CRepeaterHandler::linkFailed(DSTAR_PROTOCOL protocol, const std::string& ca if (protocol == DP_DEXTRA) { switch (m_linkStatus) { case LS_LINKED_DEXTRA: - wxLogMessage("DExtra link to %s has failed, relinking", m_linkRepeater.c_str()); + CLog::logInfo("DExtra link to %s has failed, relinking", m_linkRepeater.c_str()); m_linkStatus = LS_LINKING_DEXTRA; writeLinkingTo(m_linkRepeater); triggerInfo(); @@ -1765,7 +1765,7 @@ bool CRepeaterHandler::linkFailed(DSTAR_PROTOCOL protocol, const std::string& ca if (protocol == DP_DPLUS) { switch (m_linkStatus) { case LS_LINKED_DPLUS: - wxLogMessage("D-Plus link to %s has failed, relinking", m_linkRepeater.c_str()); + CLog::logInfo("D-Plus link to %s has failed, relinking", m_linkRepeater.c_str()); m_linkStatus = LS_LINKING_DPLUS; writeLinkingTo(m_linkRepeater); triggerInfo(); @@ -1782,14 +1782,14 @@ bool CRepeaterHandler::linkFailed(DSTAR_PROTOCOL protocol, const std::string& ca if (protocol == DP_DCS) { switch (m_linkStatus) { case LS_LINKED_DCS: - wxLogMessage("DCS link to %s has failed, relinking", m_linkRepeater.c_str()); + CLog::logInfo("DCS link to %s has failed, relinking", m_linkRepeater.c_str()); m_linkStatus = LS_LINKING_DCS; writeLinkingTo(m_linkRepeater); triggerInfo(); return true; case LS_LINKED_LOOPBACK: - wxLogMessage("Loopback link to %s has failed, relinking", m_linkRepeater.c_str()); + CLog::logInfo("Loopback link to %s has failed, relinking", m_linkRepeater.c_str()); m_linkStatus = LS_LINKING_LOOPBACK; writeLinkingTo(m_linkRepeater); triggerInfo(); @@ -1810,7 +1810,7 @@ bool CRepeaterHandler::linkFailed(DSTAR_PROTOCOL protocol, const std::string& ca void CRepeaterHandler::linkRefused(DSTAR_PROTOCOL protocol, const std::string& callsign) { if (protocol == DP_DEXTRA && callsign == m_linkRepeater) { - wxLogMessage("DExtra link to %s was refused", m_linkRepeater.c_str()); + CLog::logInfo("DExtra link to %s was refused", m_linkRepeater.c_str()); m_linkRepeater.clear(); m_linkStatus = LS_NONE; writeIsBusy(callsign); @@ -1818,7 +1818,7 @@ void CRepeaterHandler::linkRefused(DSTAR_PROTOCOL protocol, const std::string& c } if (protocol == DP_DPLUS && callsign == m_linkRepeater) { - wxLogMessage("D-Plus link to %s was refused", m_linkRepeater.c_str()); + CLog::logInfo("D-Plus link to %s was refused", m_linkRepeater.c_str()); m_linkRepeater.clear(); m_linkStatus = LS_NONE; writeIsBusy(callsign); @@ -1827,9 +1827,9 @@ void CRepeaterHandler::linkRefused(DSTAR_PROTOCOL protocol, const std::string& c if (protocol == DP_DCS && callsign == m_linkRepeater) { if (m_linkStatus == LS_LINKED_DCS || m_linkStatus == LS_LINKING_DCS) - wxLogMessage("DCS link to %s was refused", m_linkRepeater.c_str()); + CLog::logInfo("DCS link to %s was refused", m_linkRepeater.c_str()); else - wxLogMessage("Loopback link to %s was refused", m_linkRepeater.c_str()); + CLog::logInfo("Loopback link to %s was refused", m_linkRepeater.c_str()); m_linkRepeater.clear(); m_linkStatus = LS_NONE; writeIsBusy(callsign); @@ -1842,7 +1842,7 @@ void CRepeaterHandler::link(RECONNECT reconnect, const std::string& reflector) #ifdef USE_CCS // CCS removal if (m_linkStatus == LS_LINKING_CCS || m_linkStatus == LS_LINKED_CCS) { - wxLogMessage(wxT("Dropping CCS link to %s"), m_linkRepeater.c_str()); + CLog::logInfo(wxT("Dropping CCS link to %s"), m_linkRepeater.c_str()); m_ccsHandler->stopLink(); @@ -1899,7 +1899,7 @@ void CRepeaterHandler::link(RECONNECT reconnect, const std::string& reflector) // Handle unlinking if (m_linkStatus != LS_NONE && (reflector.empty() || reflector == " ")) { - wxLogMessage("Unlinking %s from %s", m_rptCallsign.c_str(), m_linkRepeater.c_str()); + CLog::logInfo("Unlinking %s from %s", m_rptCallsign.c_str(), m_linkRepeater.c_str()); CDExtraHandler::unlink(this); CDPlusHandler::unlink(this); @@ -1914,7 +1914,7 @@ void CRepeaterHandler::link(RECONNECT reconnect, const std::string& reflector) return; } - wxLogMessage("Linking %s to %s", m_rptCallsign.c_str(), reflector.c_str()); + CLog::logInfo("Linking %s to %s", m_rptCallsign.c_str(), reflector.c_str()); // Check for just a change of letter if (m_linkStatus != LS_NONE) { @@ -1996,7 +1996,7 @@ void CRepeaterHandler::unlink(PROTOCOL protocol, const std::string& reflector) #endif if (m_linkReconnect == RECONNECT_FIXED && m_linkRepeater == (reflector)) { - wxLogMessage("Cannot unlink %s because it is fixed", reflector.c_str()); + CLog::logInfo("Cannot unlink %s because it is fixed", reflector.c_str()); return; } @@ -2025,7 +2025,7 @@ void CRepeaterHandler::g2CommandHandler(const std::string& callsign, const std:: if (callsign.substr(0,1) == "/") { if (m_irc == NULL) { - wxLogMessage("%s is trying to G2 route with ircDDB disabled", user.c_str()); + CLog::logInfo("%s is trying to G2 route with ircDDB disabled", user.c_str()); m_g2Status = G2_LOCAL; return; } @@ -2037,18 +2037,18 @@ void CRepeaterHandler::g2CommandHandler(const std::string& callsign, const std:: repeater += callsign.substr(callsign.length() - 1, 1); if (repeater == m_rptCallsign) { - wxLogMessage("%s is trying to G2 route to self, ignoring", user.c_str()); + CLog::logInfo("%s is trying to G2 route to self, ignoring", user.c_str()); m_g2Status = G2_LOCAL; return; } if (repeater.substr(0,3U) == "REF" || repeater.substr(0,3U) == "XRF" || repeater.substr(0,3U) == "DCS") { - wxLogMessage("%s is trying to G2 route to reflector %s, ignoring", user.c_str(), repeater.c_str()); + CLog::logInfo("%s is trying to G2 route to reflector %s, ignoring", user.c_str(), repeater.c_str()); m_g2Status = G2_LOCAL; return; } - wxLogMessage("%s is trying to G2 route to repeater %s", user.c_str(), repeater.c_str()); + CLog::logInfo("%s is trying to G2 route to repeater %s", user.c_str(), repeater.c_str()); m_g2Repeater = repeater; m_g2User = wxT("CQCQCQ "); @@ -2071,19 +2071,19 @@ void CRepeaterHandler::g2CommandHandler(const std::string& callsign, const std:: } } else if (string_right(callsign, 1) != "L" && string_right(callsign, 1) == "U") { if (m_irc == NULL) { - wxLogMessage("%s is trying to G2 route with ircDDB disabled", user.c_str()); + CLog::logInfo("%s is trying to G2 route with ircDDB disabled", user.c_str()); m_g2Status = G2_LOCAL; return; } // This a callsign route if (callsign.substr(0,3U) == "REF" || callsign.substr(0,3U) == "XRF" || callsign.substr(0,3U) == "DCS") { - wxLogMessage("%s is trying to G2 route to reflector %s, ignoring", user.c_str(), callsign.c_str()); + CLog::logInfo("%s is trying to G2 route to reflector %s, ignoring", user.c_str(), callsign.c_str()); m_g2Status = G2_LOCAL; return; } - wxLogMessage("%s is trying to G2 route to callsign %s", user.c_str(), callsign.c_str()); + CLog::logInfo("%s is trying to G2 route to callsign %s", user.c_str(), callsign.c_str()); CUserData* data = m_cache->findUser(callsign); @@ -2150,7 +2150,7 @@ void CRepeaterHandler::reflectorCommandHandler(const std::string& callsign, cons if (m_linkStatus == LS_NONE) return; - wxLogMessage("Unlink command issued via %s by %s", type.c_str(), user.c_str()); + CLog::logInfo("Unlink command issued via %s by %s", type.c_str(), user.c_str()); CDExtraHandler::unlink(this); CDPlusHandler::unlink(this); @@ -2183,12 +2183,12 @@ void CRepeaterHandler::reflectorCommandHandler(const std::string& callsign, cons // We can't link to ourself if (reflector == m_rptCallsign) { - wxLogMessage("%s is trying to link with self via %s, ignoring", user.c_str(), type.c_str()); + CLog::logInfo("%s is trying to link with self via %s, ignoring", user.c_str(), type.c_str()); triggerInfo(); return; } - wxLogMessage("Link command from %s to %s issued via %s by %s", m_rptCallsign.c_str(), reflector.c_str(), type.c_str(), user.c_str()); + CLog::logInfo("Link command from %s to %s issued via %s by %s", m_rptCallsign.c_str(), reflector.c_str(), type.c_str(), user.c_str()); // Check for just a change of letter if (m_linkStatus != LS_NONE) { @@ -2268,7 +2268,7 @@ void CRepeaterHandler::linkInt(const std::string& callsign) // Are we trying to link to an unknown DExtra, D-Plus, or DCS reflector? if (data == NULL && (callsign.substr(0,3U) == "REF" || callsign.substr(0,3U) == "XRF" || callsign.substr(0,3U) == "DCS")) { - wxLogMessage("%s is unknown, ignoring link request", callsign.c_str()); + CLog::logInfo("%s is unknown, ignoring link request", callsign.c_str()); triggerInfo(); return; } @@ -2286,7 +2286,7 @@ void CRepeaterHandler::linkInt(const std::string& callsign) writeLinkingTo(m_linkRepeater); triggerInfo(); } else { - wxLogMessage("Require D-Plus for linking to %s, but D-Plus is disabled", callsign.c_str()); + CLog::logInfo("Require D-Plus for linking to %s, but D-Plus is disabled", callsign.c_str()); m_linkStatus = LS_NONE; writeNotLinked(); triggerInfo(); @@ -2300,7 +2300,7 @@ void CRepeaterHandler::linkInt(const std::string& callsign) writeLinkingTo(m_linkRepeater); triggerInfo(); } else { - wxLogMessage("Require DCS for linking to %s, but DCS is disabled", callsign.c_str()); + CLog::logInfo("Require DCS for linking to %s, but DCS is disabled", callsign.c_str()); m_linkStatus = LS_NONE; writeNotLinked(); triggerInfo(); @@ -2321,7 +2321,7 @@ void CRepeaterHandler::linkInt(const std::string& callsign) writeLinkingTo(m_linkRepeater); triggerInfo(); } else { - wxLogMessage("Require DExtra for linking to %s, but DExtra is disabled", callsign.c_str()); + CLog::logInfo("Require DExtra for linking to %s, but DExtra is disabled", callsign.c_str()); m_linkStatus = LS_NONE; writeNotLinked(); triggerInfo(); @@ -2435,7 +2435,7 @@ void CRepeaterHandler::startupInt() // Link to a startup reflector/repeater if (m_linkAtStartup && !m_linkStartup.empty()) { - wxLogMessage("Linking %s at startup to %s", m_rptCallsign.c_str(), m_linkStartup.c_str()); + CLog::logInfo("Linking %s at startup to %s", m_rptCallsign.c_str(), m_linkStartup.c_str()); // Find the repeater to link to CRepeaterData* data = m_cache->findRepeater(m_linkStartup); @@ -2454,7 +2454,7 @@ void CRepeaterHandler::startupInt() writeLinkingTo(m_linkRepeater); triggerInfo(); } else { - wxLogMessage("Require D-Plus for linking to %s, but D-Plus is disabled", m_linkRepeater.c_str()); + CLog::logInfo("Require D-Plus for linking to %s, but D-Plus is disabled", m_linkRepeater.c_str()); m_linkStatus = LS_NONE; writeNotLinked(); triggerInfo(); @@ -2468,7 +2468,7 @@ void CRepeaterHandler::startupInt() writeLinkingTo(m_linkRepeater); triggerInfo(); } else { - wxLogMessage("Require DCS for linking to %s, but DCS is disabled", m_linkRepeater.c_str()); + CLog::logInfo("Require DCS for linking to %s, but DCS is disabled", m_linkRepeater.c_str()); m_linkStatus = LS_NONE; writeNotLinked(); triggerInfo(); @@ -2489,7 +2489,7 @@ void CRepeaterHandler::startupInt() writeLinkingTo(m_linkRepeater); triggerInfo(); } else { - wxLogMessage("Require DExtra for linking to %s, but DExtra is disabled", m_linkRepeater.c_str()); + CLog::logInfo("Require DExtra for linking to %s, but DExtra is disabled", m_linkRepeater.c_str()); m_linkStatus = LS_NONE; writeNotLinked(); triggerInfo(); diff --git a/RepeaterProtocolHandlerFactory.cpp b/RepeaterProtocolHandlerFactory.cpp index f9113b0..845a95e 100644 --- a/RepeaterProtocolHandlerFactory.cpp +++ b/RepeaterProtocolHandlerFactory.cpp @@ -37,7 +37,7 @@ IRepeaterProtocolHandler * CRepeaterHandlerFactory::getRepeaterProtocolHandler(H CIcomRepeaterProtocolHandler * icomRepeaterHandler = new CIcomRepeaterProtocolHandler(gatewayConfig.icomAddress, gatewayConfig.icomPort, repeaterAddress, repeaterPort); bool res = icomRepeaterHandler->open(); if (!res) { - wxLogError("Cannot open the Icom repeater protocol handler"); + CLog::logError("Cannot open the Icom repeater protocol handler"); delete icomRepeaterHandler; icomRepeaterHandler = NULL; } @@ -50,7 +50,7 @@ IRepeaterProtocolHandler * CRepeaterHandlerFactory::getRepeaterProtocolHandler(H CHBRepeaterProtocolHandler * hbRepeaterHandler = new CHBRepeaterProtocolHandler(gatewayConfig.hbAddress, gatewayConfig.hbPort); bool res = hbRepeaterHandler->open(); if (!res) { - wxLogError("Cannot open the Homebrew repeater protocol handler"); + CLog::logError("Cannot open the Homebrew repeater protocol handler"); delete hbRepeaterHandler; hbRepeaterHandler = NULL; } @@ -63,7 +63,7 @@ IRepeaterProtocolHandler * CRepeaterHandlerFactory::getRepeaterProtocolHandler(H CDummyRepeaterProtocolHandler * dummyRepeaterHandler = new CDummyRepeaterProtocolHandler; bool res = dummyRepeaterHandler->open(); if (!res) { - wxLogError("Cannot open the Dummy repeater protocol handler"); + CLog::logError("Cannot open the Dummy repeater protocol handler"); delete dummyRepeaterHandler; dummyRepeaterHandler = NULL; } diff --git a/TCPReaderWriterClient.cpp b/TCPReaderWriterClient.cpp index 581c699..e21da7a 100644 --- a/TCPReaderWriterClient.cpp +++ b/TCPReaderWriterClient.cpp @@ -25,7 +25,7 @@ #include "TCPReaderWriterClient.h" #include "UDPReaderWriter.h" #include "Utils.h" - +#include "Log.h" CTCPReaderWriterClient::CTCPReaderWriterClient(const std::string& address, unsigned int port, const std::string& localAddress) : m_address(address), @@ -77,7 +77,7 @@ bool CTCPReaderWriterClient::open() m_fd = ::socket(PF_INET, SOCK_STREAM, 0); if (m_fd < 0) { - printf("Cannot create the TCP client socket, err=%d\n", errno); + CLog::logInfo("Cannot create the TCP client socket, err=%d\n", errno); return false; } @@ -88,13 +88,13 @@ bool CTCPReaderWriterClient::open() addr.sin_port = 0U; addr.sin_addr.s_addr = ::inet_addr(m_localAddress.c_str()); if (addr.sin_addr.s_addr == INADDR_NONE) { - printf("The address is invalid - %s\n", m_localAddress.c_str()); + CLog::logInfo("The address is invalid - %s\n", m_localAddress.c_str()); close(); return false; } if (::bind(m_fd, (sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { - printf("Cannot bind the TCP client address, err=%d\n", errno); + CLog::logInfo("Cannot bind the TCP client address, err=%d\n", errno); close(); return false; } @@ -112,14 +112,14 @@ bool CTCPReaderWriterClient::open() } if (::connect(m_fd, (sockaddr*)&addr, sizeof(struct sockaddr_in)) == -1) { - printf("Cannot connect the TCP client socket, err=%d\n", errno); + CLog::logInfo("Cannot connect the TCP client socket, err=%d\n", errno); close(); return false; } int noDelay = 1; if (::setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&noDelay, sizeof(noDelay)) == -1) { - printf("Cannot set the TCP client socket option, err=%d\n", errno); + CLog::logInfo("Cannot set the TCP client socket option, err=%d\n", errno); close(); return false; } @@ -145,7 +145,7 @@ int CTCPReaderWriterClient::read(unsigned char* buffer, unsigned int length, uns int ret = ::select(m_fd + 1, &readFds, NULL, NULL, &tv); if (ret < 0) { - printf("Error returned from TCP client select, err=%d\n", errno); + CLog::logInfo("Error returned from TCP client select, err=%d\n", errno); return -1; } @@ -156,7 +156,7 @@ int CTCPReaderWriterClient::read(unsigned char* buffer, unsigned int length, uns if (len == 0) { return -2; } else if (len < 0) { - printf("Error returned from recv, err=%d\n", errno); + CLog::logInfo("Error returned from recv, err=%d\n", errno); return -1; } @@ -192,7 +192,7 @@ bool CTCPReaderWriterClient::write(const unsigned char* buffer, unsigned int len ssize_t ret = ::send(m_fd, (char *)buffer, length, 0); if (ret != ssize_t(length)) { - printf("Error returned from send, err=%d\n", errno); + CLog::logInfo("Error returned from send, err=%d\n", errno); return false; } diff --git a/UDPReaderWriter.cpp b/UDPReaderWriter.cpp index 5416cd6..9fcc828 100644 --- a/UDPReaderWriter.cpp +++ b/UDPReaderWriter.cpp @@ -20,6 +20,7 @@ #include #include #include "UDPReaderWriter.h" +#include "Log.h" CUDPReaderWriter::CUDPReaderWriter(const std::string& address, unsigned int port) : m_address(address), @@ -56,7 +57,7 @@ in_addr CUDPReaderWriter::lookup(const std::string& hostname) return addr; } - printf("Cannot find address for host %s\n", hostname.c_str()); + CLog::logInfo("Cannot find address for host %s\n", hostname.c_str()); addr.s_addr = INADDR_NONE; return addr; @@ -66,7 +67,7 @@ bool CUDPReaderWriter::open() { m_fd = ::socket(PF_INET, SOCK_DGRAM, 0); if (m_fd < 0) { - printf("Cannot create the UDP socket, err: %s\n", strerror(errno)); + CLog::logInfo("Cannot create the UDP socket, err: %s\n", strerror(errno)); return false; } @@ -80,19 +81,19 @@ bool CUDPReaderWriter::open() if (m_address.size()) { addr.sin_addr.s_addr = ::inet_addr(m_address.c_str()); if (addr.sin_addr.s_addr == INADDR_NONE) { - printf("The address is invalid - %s\n", m_address.c_str()); + CLog::logInfo("The address is invalid - %s\n", m_address.c_str()); return false; } } int reuse = 1; if (::setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) == -1) { - printf("Cannot set the UDP socket option (port: %u), err: %s\n", m_port, strerror(errno)); + CLog::logInfo("Cannot set the UDP socket option (port: %u), err: %s\n", m_port, strerror(errno)); return false; } if (::bind(m_fd, (sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { - printf("Cannot bind the UDP address (port: %u), err: %s\n", m_port, strerror(errno)); + CLog::logInfo("Cannot bind the UDP address (port: %u), err: %s\n", m_port, strerror(errno)); return false; } } @@ -114,7 +115,7 @@ int CUDPReaderWriter::read(unsigned char* buffer, unsigned int length, in_addr& int ret = ::select(m_fd + 1, &readFds, NULL, NULL, &tv); if (ret < 0) { - printf("Error returned from UDP select (port: %u), err: %s\n", m_port, strerror(errno)); + CLog::logInfo("Error returned from UDP select (port: %u), err: %s\n", m_port, strerror(errno)); return -1; } @@ -126,7 +127,7 @@ int CUDPReaderWriter::read(unsigned char* buffer, unsigned int length, in_addr& ssize_t len = ::recvfrom(m_fd, (char*)buffer, length, 0, (sockaddr *)&addr, &size); if (len <= 0) { - printf("Error returned from recvfrom (port: %u), err: %s\n", m_port, strerror(errno)); + CLog::logInfo("Error returned from recvfrom (port: %u), err: %s\n", m_port, strerror(errno)); return -1; } @@ -147,7 +148,7 @@ bool CUDPReaderWriter::write(const unsigned char* buffer, unsigned int length, c ssize_t ret = ::sendto(m_fd, (char *)buffer, length, 0, (sockaddr *)&addr, sizeof(sockaddr_in)); if (ret < 0) { - printf("Error returned from sendto (port: %u), err: %s\n", m_port, strerror(errno)); + CLog::logInfo("Error returned from sendto (port: %u), err: %s\n", m_port, strerror(errno)); return false; } diff --git a/Utils.cpp b/Utils.cpp index 43f0c63..ebb1c57 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -29,13 +29,14 @@ #include #include "Utils.h" +#include "Log.h" void CUtils::dump(const char* title, const bool* data, unsigned int length) { assert(title != NULL); assert(data != NULL); - printf("%s\n", title); + CLog::logInfo("%s\n", title); unsigned int offset = 0U; @@ -69,7 +70,7 @@ void CUtils::dump(const char* title, const bool* data, unsigned int length) output += "*'"; - printf("%04X: %s\n", offset / 8U, output.c_str()); + CLog::logInfo("%04X: %s\n", offset / 8U, output.c_str()); offset += 128U; } @@ -80,7 +81,7 @@ void CUtils::dumpRev(const char* title, const bool* data, unsigned int length) assert(title != NULL); assert(data != NULL); - printf("%s\n", title); + CLog::logInfo("%s\n", title); unsigned int offset = 0U; @@ -114,7 +115,7 @@ void CUtils::dumpRev(const char* title, const bool* data, unsigned int length) output += "*"; - printf("%04X: %s\n", offset / 8U, output.c_str()); + CLog::logInfo("%04X: %s\n", offset / 8U, output.c_str()); offset += 128U; } @@ -125,7 +126,7 @@ void CUtils::dump(const char* title, const unsigned char* data, unsigned int len assert(title != NULL); assert(data != NULL); - printf("%s\n", title); + CLog::logInfo("%s\n", title); unsigned int offset = 0U; @@ -156,7 +157,7 @@ void CUtils::dump(const char* title, const unsigned char* data, unsigned int len output += "*"; - printf("%04X: %s\n", offset, output.c_str()); + CLog::logInfo("%04X: %s\n", offset, output.c_str()); offset += 16U; @@ -374,7 +375,7 @@ int CUtils::getAllIPV4Addresses(const char *name, unsigned short port, unsigned return 0; } else { std::string e(gai_strerror(r)); - printf("getaddrinfo: %s\n", e.c_str()); + CLog::logInfo("getaddrinfo: %s\n", e.c_str()); return 1; } } diff --git a/VersionUnit.cpp b/VersionUnit.cpp index a6f1452..865aebd 100644 --- a/VersionUnit.cpp +++ b/VersionUnit.cpp @@ -28,6 +28,7 @@ #include "HeaderData.h" #include "Version.h" #include "Utils.h" +#include "Log.h" const unsigned int NUM_FRAMES = 20U; @@ -47,7 +48,7 @@ m_out(0U) char vstr[32]; snprintf(vstr, 32, "ircDDB GW - %s", VERSION.substr(0, 8).c_str()); - printf("Version text set to \"%s\"\n", vstr); + CLog::logInfo("Version text set to \"%s\"\n", vstr); CSlowDataEncoder encoder; encoder.setTextData(std::string(vstr));