mirror of
https://github.com/g4klx/ircDDBGateway.git
synced 2025-12-06 05:32:02 +01:00
Merge pull request #51 from sq7lrx/container-logging
Adds console logging option to ircddbgatewayd
This commit is contained in:
commit
52c9c48140
|
|
@ -53,6 +53,9 @@
|
|||
<ClCompile Include="ConnectData.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ConsoleLogger.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DCSHandler.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
|
@ -259,6 +262,9 @@
|
|||
<ClInclude Include="ConnectData.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ConsoleLogger.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DCSHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
|||
48
Common/ConsoleLogger.cpp
Normal file
48
Common/ConsoleLogger.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2002,2003,2009,2011,2012,2019 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2020 by Adam Kolakowski SQ7LRX
|
||||
*
|
||||
* 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 "ConsoleLogger.h"
|
||||
|
||||
const char CConsoleLogger::S_LEVELS[] = "FEWMMIDTPU";
|
||||
|
||||
CConsoleLogger::CConsoleLogger() :
|
||||
wxLog(),
|
||||
m_stdout(new wxMessageOutputStderr(stdout)),
|
||||
m_stderr(new wxMessageOutputStderr(stderr))
|
||||
{
|
||||
}
|
||||
|
||||
CConsoleLogger::~CConsoleLogger()
|
||||
{
|
||||
}
|
||||
|
||||
void CConsoleLogger::DoLogRecord(wxLogLevel level, const wxString& msg, const wxLogRecordInfo& info)
|
||||
{
|
||||
if (level > 9)
|
||||
level = 9;
|
||||
|
||||
if (level <= wxLOG_Error) {
|
||||
m_stderr->Printf(wxT("%c: %s\n"), CConsoleLogger::S_LEVELS[level], msg.c_str());
|
||||
} else {
|
||||
m_stdout->Printf(wxT("%c: %s\n"), CConsoleLogger::S_LEVELS[level], msg.c_str());
|
||||
}
|
||||
|
||||
if (level == wxLOG_FatalError)
|
||||
::abort();
|
||||
}
|
||||
41
Common/ConsoleLogger.h
Normal file
41
Common/ConsoleLogger.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2002,2003,2009,2011,2012,2019 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2020 by Adam Kolakowski SQ7LRX
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ConsoleLogger_H
|
||||
#define ConsoleLogger_H
|
||||
|
||||
#include <wx/wx.h>
|
||||
|
||||
|
||||
class CConsoleLogger : public wxLog {
|
||||
public:
|
||||
CConsoleLogger();
|
||||
virtual ~CConsoleLogger();
|
||||
|
||||
virtual void DoLogRecord(wxLogLevel level, const wxString& msg, const wxLogRecordInfo& info);
|
||||
|
||||
private:
|
||||
const static char S_LEVELS[];
|
||||
|
||||
wxMessageOutput *m_stdout;
|
||||
wxMessageOutput *m_stderr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
OBJECTS = AMBEData.o AnnouncementUnit.o APRSCollector.o APRSWriter.o APRSWriterThread.o AudioUnit.o CacheManager.o CallsignList.o \
|
||||
CallsignServer.o CCITTChecksum.o CCSData.o CCSHandler.o CCSProtocolHandler.o ConnectData.o DCSHandler.o DCSProtocolHandler.o \
|
||||
CallsignServer.o CCITTChecksum.o CCSData.o CCSHandler.o CCSProtocolHandler.o ConnectData.o ConsoleLogger.o DCSHandler.o DCSProtocolHandler.o \
|
||||
DCSProtocolHandlerPool.o DDData.o DDHandler.o DExtraHandler.o DExtraProtocolHandler.o DExtraProtocolHandlerPool.o \
|
||||
DPlusAuthenticator.o DPlusHandler.o DPlusProtocolHandler.o DPlusProtocolHandlerPool.o DRATSServer.o DTMF.o \
|
||||
DummyRepeaterProtocolHandler.o DVTOOLFileReader.o EchoUnit.o G2Handler.o G2ProtocolHandler.o GatewayCache.o \
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include "APRSWriter.h"
|
||||
#include "Version.h"
|
||||
#include "Logger.h"
|
||||
#include "ConsoleLogger.h"
|
||||
#include "IRCDDB.h"
|
||||
#include "IRCDDBClient.h"
|
||||
#include "IRCDDBMultiClient.h"
|
||||
|
|
@ -48,6 +49,7 @@ const wxChar* DEBUG_SWITCH = wxT("debug");
|
|||
const wxChar* LOGDIR_OPTION = wxT("logdir");
|
||||
const wxChar* CONFDIR_OPTION = wxT("confdir");
|
||||
const wxChar* DAEMON_SWITCH = wxT("daemon");
|
||||
const wxChar* FGROUND_SWITCH = wxT("foreground");
|
||||
|
||||
const wxString LOG_BASE_NAME = wxT("ircDDBGateway");
|
||||
|
||||
|
|
@ -70,6 +72,7 @@ int main(int argc, char** argv)
|
|||
parser.AddSwitch(NOLOGGING_SWITCH, wxEmptyString, wxEmptyString, wxCMD_LINE_PARAM_OPTIONAL);
|
||||
parser.AddSwitch(DEBUG_SWITCH, wxEmptyString, wxEmptyString, wxCMD_LINE_PARAM_OPTIONAL);
|
||||
parser.AddSwitch(DAEMON_SWITCH, wxEmptyString, wxEmptyString, wxCMD_LINE_PARAM_OPTIONAL);
|
||||
parser.AddSwitch(FGROUND_SWITCH, wxEmptyString, wxEmptyString, wxCMD_LINE_PARAM_OPTIONAL);
|
||||
parser.AddOption(LOGDIR_OPTION, wxEmptyString, wxEmptyString, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
|
||||
parser.AddOption(CONFDIR_OPTION, wxEmptyString, wxEmptyString, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
|
||||
parser.AddParam(NAME_PARAM, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
|
||||
|
|
@ -83,6 +86,7 @@ int main(int argc, char** argv)
|
|||
bool nolog = parser.Found(NOLOGGING_SWITCH);
|
||||
bool debug = parser.Found(DEBUG_SWITCH);
|
||||
bool daemon = parser.Found(DAEMON_SWITCH);
|
||||
bool foreground = parser.Found(FGROUND_SWITCH);
|
||||
|
||||
wxString logDir;
|
||||
bool found = parser.Found(LOGDIR_OPTION, &logDir);
|
||||
|
|
@ -98,6 +102,12 @@ int main(int argc, char** argv)
|
|||
if (parser.GetParamCount() > 0U)
|
||||
name = parser.GetParam(0U);
|
||||
|
||||
if (daemon && foreground) {
|
||||
::fprintf(stderr, "ircddbgatewayd: -daemon and -foreground are mutually exclusive, exiting\n");
|
||||
::wxUninitialize();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (daemon) {
|
||||
pid_t pid = ::fork();
|
||||
|
||||
|
|
@ -138,7 +148,7 @@ int main(int argc, char** argv)
|
|||
::fclose(fp);
|
||||
}
|
||||
|
||||
m_gateway = new CIRCDDBGatewayAppD(nolog, debug, logDir, confDir, name);
|
||||
m_gateway = new CIRCDDBGatewayAppD(nolog, debug, foreground, logDir, confDir, name);
|
||||
if (!m_gateway->init()) {
|
||||
::wxUninitialize();
|
||||
return 1;
|
||||
|
|
@ -157,10 +167,11 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
CIRCDDBGatewayAppD::CIRCDDBGatewayAppD(bool nolog, bool debug, const wxString& logDir, const wxString& confDir, const wxString& name) :
|
||||
CIRCDDBGatewayAppD::CIRCDDBGatewayAppD(bool nolog, bool debug, bool foreground, const wxString& logDir, const wxString& confDir, const wxString& name) :
|
||||
m_name(name),
|
||||
m_nolog(nolog),
|
||||
m_debug(debug),
|
||||
m_foreground(foreground),
|
||||
m_logDir(logDir),
|
||||
m_confDir(confDir),
|
||||
m_thread(NULL),
|
||||
|
|
@ -174,7 +185,9 @@ CIRCDDBGatewayAppD::~CIRCDDBGatewayAppD()
|
|||
|
||||
bool CIRCDDBGatewayAppD::init()
|
||||
{
|
||||
if (!m_nolog) {
|
||||
if (m_foreground) {
|
||||
initLogging(new CConsoleLogger());
|
||||
} else if (!m_nolog) {
|
||||
wxString logBaseName = LOG_BASE_NAME;
|
||||
if (!m_name.IsEmpty()) {
|
||||
logBaseName.Append(wxT("_"));
|
||||
|
|
@ -184,16 +197,7 @@ bool CIRCDDBGatewayAppD::init()
|
|||
if (m_logDir.IsEmpty())
|
||||
m_logDir = wxT(LOG_DIR);
|
||||
|
||||
wxLog* log = new CLogger(m_logDir, logBaseName);
|
||||
wxLog::SetActiveTarget(log);
|
||||
|
||||
if (m_debug) {
|
||||
wxLog::SetVerbose(true);
|
||||
wxLog::SetLogLevel(wxLOG_Debug);
|
||||
} else {
|
||||
wxLog::SetVerbose(false);
|
||||
wxLog::SetLogLevel(wxLOG_Message);
|
||||
}
|
||||
initLogging(new CLogger(m_logDir, logBaseName));
|
||||
} else {
|
||||
new wxLogNull;
|
||||
}
|
||||
|
|
@ -212,14 +216,31 @@ bool CIRCDDBGatewayAppD::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
wxLogInfo(wxT("Starting ") + APPLICATION_NAME + wxT(" daemon - ") + VERSION);
|
||||
wxLogMessage(wxT("Starting ") + APPLICATION_NAME + wxT(" daemon - ") + VERSION);
|
||||
|
||||
// Log the version of wxWidgets and the Operating System
|
||||
wxLogInfo(wxT("Using wxWidgets %d.%d.%d on %s"), wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER, ::wxGetOsDescription().c_str());
|
||||
|
||||
if (!m_nolog && m_foreground) {
|
||||
wxLogWarning(wxT("Running in foreground, logging to file disabled. Use -nolog when running this application in foreground to suppress this "));
|
||||
}
|
||||
|
||||
return createThread();
|
||||
}
|
||||
|
||||
void CIRCDDBGatewayAppD::initLogging(wxLog *logger)
|
||||
{
|
||||
wxLog::SetActiveTarget(logger);
|
||||
|
||||
if (m_debug) {
|
||||
wxLog::SetVerbose(true);
|
||||
wxLog::SetLogLevel(wxLOG_Debug);
|
||||
} else {
|
||||
wxLog::SetVerbose(false);
|
||||
wxLog::SetLogLevel(wxLOG_Message);
|
||||
}
|
||||
}
|
||||
|
||||
void CIRCDDBGatewayAppD::run()
|
||||
{
|
||||
m_thread->run();
|
||||
|
|
@ -878,7 +899,7 @@ bool CIRCDDBGatewayAppD::createThread()
|
|||
bool xlxEnabled;
|
||||
wxString xlxHostsFileUrl;
|
||||
config.getXLX(xlxEnabled, xlxHostsFileUrl);
|
||||
wxLogInfo(wxT("XLX enabled: %d, Override Local %d, Hosts file url: %s"), int(xlxEnabled), xlxHostsFileUrl.c_str());
|
||||
wxLogInfo(wxT("XLX enabled: %d, Hosts file url: %s"), int(xlxEnabled), xlxHostsFileUrl.c_str());
|
||||
|
||||
if (repeaterBand1.Len() > 1U || repeaterBand2.Len() > 1U ||
|
||||
repeaterBand3.Len() > 1U || repeaterBand4.Len() > 1U) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
class CIRCDDBGatewayAppD {
|
||||
|
||||
public:
|
||||
CIRCDDBGatewayAppD(bool nolog, bool debug, const wxString& logDir, const wxString& confDir, const wxString& name);
|
||||
CIRCDDBGatewayAppD(bool nolog, bool debug, bool foreground, const wxString& logDir, const wxString& confDir, const wxString& name);
|
||||
~CIRCDDBGatewayAppD();
|
||||
|
||||
bool init();
|
||||
|
|
@ -41,12 +41,14 @@ private:
|
|||
wxString m_name;
|
||||
bool m_nolog;
|
||||
bool m_debug;
|
||||
bool m_foreground;
|
||||
wxString m_logDir;
|
||||
wxString m_confDir;
|
||||
CIRCDDBGatewayThread* m_thread;
|
||||
wxSingleInstanceChecker* m_checker;
|
||||
|
||||
bool createThread();
|
||||
void initLogging(wxLog *logger);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue