add debug param to reduce logs

This commit is contained in:
Shawn Chain 2018-10-07 00:47:15 +08:00
parent 1e933b4120
commit e3facce658
5 changed files with 31 additions and 13 deletions

View file

@ -80,7 +80,13 @@ void CLogger::DoLogRecord(wxLogLevel level, const wxString& msg, const wxLogReco
default: letter = wxT("U"); break;
}
struct tm* tm = ::gmtime(&info.timestamp);
bool utc = false;
struct tm* tm;
if (utc){
tm = ::gmtime(&info.timestamp);
}else{
tm = ::localtime(&info.timestamp);
}
wxString message;
message.Printf(wxT("%s: %04d-%02d-%02d %02d:%02d:%02d: %s\n"), letter.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, msg.c_str());

View file

@ -29,6 +29,7 @@ wxString CXLXHostsFileDownloader::Download(const wxString & xlxHostsFileURL)
{
#ifdef XLX_USE_WGET
wxString xlxHostsFileName = wxFileName::CreateTempFileName(_T("XLX_Hosts_"));
wxLogMessage(_T("Downloading XLX host file..."));
wxString commandLine = _T("wget -q -O ") + xlxHostsFileName + _T(" ") + xlxHostsFileURL;
bool execResult = wxShell(commandLine);

View file

@ -49,6 +49,7 @@ const wxChar* NOLOGGING_SWITCH = wxT("nolog");
const wxChar* LOGDIR_OPTION = wxT("logdir");
const wxChar* CONFDIR_OPTION = wxT("confdir");
const wxChar* DAEMON_SWITCH = wxT("daemon");
const wxChar* DEBUG_SWITCH = wxT("debug");
const wxString LOG_BASE_NAME = wxT(LOG_BASE);
@ -70,6 +71,7 @@ int main(int argc, char** argv)
wxCmdLineParser parser(argc, argv);
parser.AddSwitch(NOLOGGING_SWITCH, wxEmptyString, wxEmptyString, wxCMD_LINE_PARAM_OPTIONAL);
parser.AddSwitch(DAEMON_SWITCH, wxEmptyString, wxEmptyString, wxCMD_LINE_PARAM_OPTIONAL);
parser.AddSwitch(DEBUG_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);
@ -82,6 +84,7 @@ int main(int argc, char** argv)
bool nolog = parser.Found(NOLOGGING_SWITCH);
bool daemon = parser.Found(DAEMON_SWITCH);
bool debug = parser.Found(DEBUG_SWITCH);
wxString logDir;
bool found = parser.Found(LOGDIR_OPTION, &logDir);
@ -137,7 +140,7 @@ int main(int argc, char** argv)
::fclose(fp);
}
m_gateway = new CIRCDDBGatewayAppD(nolog, logDir, confDir, name);
m_gateway = new CIRCDDBGatewayAppD(nolog, debug, logDir, confDir, name);
if (!m_gateway->init()) {
::wxUninitialize();
return 1;
@ -156,9 +159,10 @@ int main(int argc, char** argv)
return 0;
}
CIRCDDBGatewayAppD::CIRCDDBGatewayAppD(bool nolog, const wxString& logDir, const wxString& confDir, const wxString& name) :
CIRCDDBGatewayAppD::CIRCDDBGatewayAppD(bool nolog, bool debug, const wxString& logDir, const wxString& confDir, const wxString& name) :
m_name(name),
m_nolog(nolog),
m_debug(debug),
m_logDir(logDir),
m_confDir(confDir),
m_thread(NULL),
@ -184,7 +188,13 @@ bool CIRCDDBGatewayAppD::init()
wxLog* log = new CLogger(m_logDir, logBaseName);
wxLog::SetActiveTarget(log);
if (m_debug){
wxLog::SetVerbose();
wxLog::SetLogLevel(wxLOG_Debug);
}else{
wxLog::SetVerbose(false);
wxLog::SetLogLevel(wxLOG_Message);
}
} else {
new wxLogNull;
}

View file

@ -28,7 +28,7 @@
class CIRCDDBGatewayAppD {
public:
CIRCDDBGatewayAppD(bool nolog, const wxString& logDir, const wxString& confDir, const wxString& name);
CIRCDDBGatewayAppD(bool nolog, bool debug, const wxString& logDir, const wxString& confDir, const wxString& name);
~CIRCDDBGatewayAppD();
bool init();
@ -40,6 +40,7 @@ public:
private:
wxString m_name;
bool m_nolog;
bool m_debug;
wxString m_logDir;
wxString m_confDir;
CIRCDDBGatewayThread* m_thread;

View file

@ -684,19 +684,19 @@ void CIRCDDBGatewayThread::processIrcDDB()
case 0:
case 10:
if (m_lastStatus != IS_DISCONNECTED) {
wxLogInfo(wxT("Disconnected from ircDDB"));
wxLogMessage(wxT("Disconnected from ircDDB"));
m_lastStatus = IS_DISCONNECTED;
}
break;
case 7:
if (m_lastStatus != IS_CONNECTED) {
wxLogInfo(wxT("Connected to ircDDB"));
wxLogMessage(wxT("Connected to ircDDB"));
m_lastStatus = IS_CONNECTED;
}
break;
default:
if (m_lastStatus != IS_CONNECTING) {
wxLogInfo(wxT("Connecting to ircDDB"));
wxLogMessage(wxT("Connecting to ircDDB"));
m_lastStatus = IS_CONNECTING;
}
break;
@ -717,10 +717,10 @@ void CIRCDDBGatewayThread::processIrcDDB()
break;
if (!address.IsEmpty()) {
wxLogMessage(wxT("USER: %s %s %s %s"), user.c_str(), repeater.c_str(), gateway.c_str(), address.c_str());
wxLogInfo(wxT("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);
} else {
wxLogMessage(wxT("USER: %s NOT FOUND"), user.c_str());
wxLogInfo(wxT("USER: %s NOT FOUND"), user.c_str());
}
}
break;
@ -733,7 +733,7 @@ void CIRCDDBGatewayThread::processIrcDDB()
CRepeaterHandler::resolveRepeater(repeater, gateway, address, DP_DEXTRA);
if (!address.IsEmpty()) {
wxLogMessage(wxT("REPEATER: %s %s %s"), repeater.c_str(), gateway.c_str(), address.c_str());
wxLogInfo(wxT("REPEATER: %s %s %s"), repeater.c_str(), gateway.c_str(), address.c_str());
m_cache.updateRepeater(repeater, gateway, address, DP_DEXTRA, false, false);
} else {
wxLogMessage(wxT("REPEATER: %s NOT FOUND"), repeater.c_str());
@ -750,7 +750,7 @@ void CIRCDDBGatewayThread::processIrcDDB()
CDExtraHandler::gatewayUpdate(gateway, address);
CDPlusHandler::gatewayUpdate(gateway, address);
if (!address.IsEmpty()) {
wxLogMessage(wxT("GATEWAY: %s %s"), gateway.c_str(), address.c_str());
wxLogInfo(wxT("GATEWAY: %s %s"), gateway.c_str(), address.c_str());
m_cache.updateGateway(gateway, address, DP_DEXTRA, false, false);
} else {
wxLogMessage(wxT("GATEWAY: %s NOT FOUND"), gateway.c_str());
@ -794,7 +794,7 @@ void CIRCDDBGatewayThread::processRepeater(IRepeaterProtocolHandler* handler)
if (!repeater.IsSameAs(user)) {
CRepeaterHandler* handler = CRepeaterHandler::findDVRepeater(repeater);
if (handler == NULL)
wxLogMessage(wxT("Heard received from unknown repeater, %s"), repeater.c_str());
wxLogInfo(wxT("Heard received from unknown repeater, %s"), repeater.c_str());
else
handler->processRepeater(*heard);