Reduced code duplication (setup file logging)
This commit is contained in:
parent
f83e91f304
commit
028142bee9
|
@ -43,6 +43,9 @@ s_suspended(false)
|
||||||
CApp::~CApp()
|
CApp::~CApp()
|
||||||
{
|
{
|
||||||
delete m_args;
|
delete m_args;
|
||||||
|
|
||||||
|
CLOG->remove(m_fileLog);
|
||||||
|
delete m_fileLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
CApp::CArgsBase::CArgsBase() :
|
CApp::CArgsBase::CArgsBase() :
|
||||||
|
@ -294,3 +297,13 @@ CApp::daemonMainLoop(int, const char**)
|
||||||
#endif
|
#endif
|
||||||
return mainLoop();
|
return mainLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CApp::setupFileLogging()
|
||||||
|
{
|
||||||
|
if (argsBase().m_logFile != NULL) {
|
||||||
|
m_fileLog = new CFileLogOutputter(argsBase().m_logFile);
|
||||||
|
CLOG->insert(m_fileLog);
|
||||||
|
LOG((CLOG_DEBUG1 "logging to file (%s) enabled", argsBase().m_logFile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
class IArchTaskBarReceiver;
|
class IArchTaskBarReceiver;
|
||||||
class CBufferedLogOutputter;
|
class CBufferedLogOutputter;
|
||||||
class ILogOutputter;
|
class ILogOutputter;
|
||||||
|
class CFileLogOutputter;
|
||||||
|
|
||||||
typedef IArchTaskBarReceiver* (*CreateTaskBarReceiverFunc)(const CBufferedLogOutputter*);
|
typedef IArchTaskBarReceiver* (*CreateTaskBarReceiverFunc)(const CBufferedLogOutputter*);
|
||||||
typedef int (*StartupFunc)(int, char**);
|
typedef int (*StartupFunc)(int, char**);
|
||||||
|
@ -90,6 +91,9 @@ public:
|
||||||
bool s_suspended;
|
bool s_suspended;
|
||||||
IArchTaskBarReceiver* s_taskBarReceiver;
|
IArchTaskBarReceiver* s_taskBarReceiver;
|
||||||
|
|
||||||
|
// If --log was specified in args, then add a file logger.
|
||||||
|
void setupFileLogging();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void parseArgs(int argc, const char* const* argv, int &i);
|
virtual void parseArgs(int argc, const char* const* argv, int &i);
|
||||||
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
|
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
|
||||||
|
@ -97,6 +101,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
CArgsBase* m_args;
|
CArgsBase* m_args;
|
||||||
static CApp* s_instance;
|
static CApp* s_instance;
|
||||||
|
CFileLogOutputter* m_fileLog;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BYE "\nTry `%s --help' for more information."
|
#define BYE "\nTry `%s --help' for more information."
|
||||||
|
|
|
@ -491,13 +491,7 @@ CClientApp::mainLoop()
|
||||||
// logging to files
|
// logging to files
|
||||||
CFileLogOutputter* fileLog = NULL;
|
CFileLogOutputter* fileLog = NULL;
|
||||||
|
|
||||||
if (args().m_logFile != NULL) {
|
setupFileLogging();
|
||||||
fileLog = new CFileLogOutputter(args().m_logFile);
|
|
||||||
|
|
||||||
CLOG->insert(fileLog);
|
|
||||||
|
|
||||||
LOG((CLOG_DEBUG1 "Logging to file (%s) enabled", args().m_logFile));
|
|
||||||
}
|
|
||||||
|
|
||||||
// create socket multiplexer. this must happen after daemonization
|
// create socket multiplexer. this must happen after daemonization
|
||||||
// on unix because threads evaporate across a fork().
|
// on unix because threads evaporate across a fork().
|
||||||
|
@ -532,11 +526,6 @@ CClientApp::mainLoop()
|
||||||
updateStatus();
|
updateStatus();
|
||||||
LOG((CLOG_NOTE "stopped client"));
|
LOG((CLOG_NOTE "stopped client"));
|
||||||
|
|
||||||
if (fileLog) {
|
|
||||||
CLOG->remove(fileLog);
|
|
||||||
delete fileLog;
|
|
||||||
}
|
|
||||||
|
|
||||||
return kExitSuccess;
|
return kExitSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -728,16 +728,7 @@ int CServerApp::mainLoop()
|
||||||
// create the event queue
|
// create the event queue
|
||||||
CEventQueue eventQueue;
|
CEventQueue eventQueue;
|
||||||
|
|
||||||
// logging to files
|
setupFileLogging();
|
||||||
CFileLogOutputter* fileLog = NULL;
|
|
||||||
|
|
||||||
if (args().m_logFile != NULL) {
|
|
||||||
fileLog = new CFileLogOutputter(args().m_logFile);
|
|
||||||
|
|
||||||
CLOG->insert(fileLog);
|
|
||||||
|
|
||||||
LOG((CLOG_DEBUG1 "Logging to file (%s) enabled", args().m_logFile));
|
|
||||||
}
|
|
||||||
|
|
||||||
// if configuration has no screens then add this system
|
// if configuration has no screens then add this system
|
||||||
// as the default
|
// as the default
|
||||||
|
@ -810,11 +801,6 @@ int CServerApp::mainLoop()
|
||||||
updateStatus();
|
updateStatus();
|
||||||
LOG((CLOG_NOTE "stopped server"));
|
LOG((CLOG_NOTE "stopped server"));
|
||||||
|
|
||||||
if (fileLog) {
|
|
||||||
CLOG->remove(fileLog);
|
|
||||||
delete fileLog;
|
|
||||||
}
|
|
||||||
|
|
||||||
return kExitSuccess;
|
return kExitSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue