refactor: Begin logging to file as soon as Windows daemon starts
This commit is contained in:
parent
a6956b9516
commit
1c42552b3b
2 changed files with 7 additions and 7 deletions
|
|
@ -62,6 +62,7 @@ int main(int argc, char **argv)
|
||||||
using enum DaemonApp::InitResult;
|
using enum DaemonApp::InitResult;
|
||||||
|
|
||||||
case StartDaemon: {
|
case StartDaemon: {
|
||||||
|
LOG_INFO("starting daemon");
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
QThread daemonThread;
|
QThread daemonThread;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -81,17 +80,17 @@ DaemonApp::~DaemonApp() = default;
|
||||||
void DaemonApp::run()
|
void DaemonApp::run()
|
||||||
{
|
{
|
||||||
if (m_foreground) {
|
if (m_foreground) {
|
||||||
LOG((CLOG_NOTE "starting daemon in foreground"));
|
LOG_INFO("starting daemon in foreground");
|
||||||
|
|
||||||
// run process in foreground instead of daemonizing.
|
// run process in foreground instead of daemonizing.
|
||||||
// useful for debugging.
|
// useful for debugging.
|
||||||
mainLoop(m_foreground);
|
mainLoop(m_foreground);
|
||||||
} else {
|
} else {
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
LOG((CLOG_NOTE "daemonizing windows service"));
|
LOG_INFO("daemonizing windows service");
|
||||||
ARCH->daemonize(kAppName, winMainLoopStatic);
|
ARCH->daemonize(kAppName, winMainLoopStatic);
|
||||||
#elif SYSAPI_UNIX
|
#elif SYSAPI_UNIX
|
||||||
LOG((CLOG_NOTE "daemonizing unix service"));
|
LOG_INFO("daemonizing unix service");
|
||||||
ARCH->daemonize(kAppName, unixMainLoopStatic);
|
ARCH->daemonize(kAppName, unixMainLoopStatic);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -171,6 +170,9 @@ DaemonApp::InitResult DaemonApp::init(IEventQueue *events, int argc, char **argv
|
||||||
|
|
||||||
m_events = events;
|
m_events = events;
|
||||||
|
|
||||||
|
m_fileLogOutputter = new FileLogOutputter(logFilename().c_str()); // NOSONAR - Adopted by `Log`
|
||||||
|
CLOG->insert(m_fileLogOutputter);
|
||||||
|
|
||||||
// default log level to system setting.
|
// default log level to system setting.
|
||||||
if (string logLevel = ARCH->setting("LogLevel"); logLevel != "")
|
if (string logLevel = ARCH->setting("LogLevel"); logLevel != "")
|
||||||
CLOG->setFilter(logLevel.c_str());
|
CLOG->setFilter(logLevel.c_str());
|
||||||
|
|
@ -234,9 +236,6 @@ void DaemonApp::mainLoop(bool foreground)
|
||||||
try {
|
try {
|
||||||
DAEMON_RUNNING(true);
|
DAEMON_RUNNING(true);
|
||||||
|
|
||||||
m_fileLogOutputter = new FileLogOutputter(logFilename().c_str()); // NOSONAR - Adopted by `Log`
|
|
||||||
CLOG->insert(m_fileLogOutputter);
|
|
||||||
|
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
m_watchdog = std::make_unique<MSWindowsWatchdog>(false, foreground);
|
m_watchdog = std::make_unique<MSWindowsWatchdog>(false, foreground);
|
||||||
m_watchdog->setFileLogOutputter(m_fileLogOutputter);
|
m_watchdog->setFileLogOutputter(m_fileLogOutputter);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue