refactor: Begin logging to file as soon as Windows daemon starts

This commit is contained in:
Nick Bolton
2025-02-24 14:05:02 +00:00
parent a6956b9516
commit 1c42552b3b
2 changed files with 7 additions and 7 deletions

View File

@ -62,6 +62,7 @@ int main(int argc, char **argv)
using enum DaemonApp::InitResult;
case StartDaemon: {
LOG_INFO("starting daemon");
QCoreApplication app(argc, argv);
QThread daemonThread;

View File

@ -28,7 +28,6 @@
#include <filesystem>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
using namespace std;
@ -81,17 +80,17 @@ DaemonApp::~DaemonApp() = default;
void DaemonApp::run()
{
if (m_foreground) {
LOG((CLOG_NOTE "starting daemon in foreground"));
LOG_INFO("starting daemon in foreground");
// run process in foreground instead of daemonizing.
// useful for debugging.
mainLoop(m_foreground);
} else {
#if SYSAPI_WIN32
LOG((CLOG_NOTE "daemonizing windows service"));
LOG_INFO("daemonizing windows service");
ARCH->daemonize(kAppName, winMainLoopStatic);
#elif SYSAPI_UNIX
LOG((CLOG_NOTE "daemonizing unix service"));
LOG_INFO("daemonizing unix service");
ARCH->daemonize(kAppName, unixMainLoopStatic);
#endif
}
@ -171,6 +170,9 @@ DaemonApp::InitResult DaemonApp::init(IEventQueue *events, int argc, char **argv
m_events = events;
m_fileLogOutputter = new FileLogOutputter(logFilename().c_str()); // NOSONAR - Adopted by `Log`
CLOG->insert(m_fileLogOutputter);
// default log level to system setting.
if (string logLevel = ARCH->setting("LogLevel"); logLevel != "")
CLOG->setFilter(logLevel.c_str());
@ -234,9 +236,6 @@ void DaemonApp::mainLoop(bool foreground)
try {
DAEMON_RUNNING(true);
m_fileLogOutputter = new FileLogOutputter(logFilename().c_str()); // NOSONAR - Adopted by `Log`
CLOG->insert(m_fileLogOutputter);
#if SYSAPI_WIN32
m_watchdog = std::make_unique<MSWindowsWatchdog>(false, foreground);
m_watchdog->setFileLogOutputter(m_fileLogOutputter);