From 53bbd08fd386e3fa72c2592966c75ae033155d9d Mon Sep 17 00:00:00 2001 From: Mykhailo Pylyp Date: Wed, 18 Nov 2020 20:25:20 +0200 Subject: [PATCH] Adjustments for runner process logging (#8112) --- src/common/logger/logger.cpp | 3 +-- src/common/logger/logger.h | 7 +++++++ src/common/logger/logger_settings.h | 6 +++++- src/modules/launcher/Microsoft.Launcher/dllmain.cpp | 4 ++-- src/runner/main.cpp | 4 ++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/common/logger/logger.cpp b/src/common/logger/logger.cpp index 7fb3e474c3..06cfd9c9cf 100644 --- a/src/common/logger/logger.cpp +++ b/src/common/logger/logger.cpp @@ -3,7 +3,6 @@ #include "pch.h" #include "framework.h" #include "logger.h" -#include "logger_settings.h" #include #include #include @@ -43,7 +42,7 @@ Logger::Logger(std::string loggerName, std::wstring logFilePath, std::wstring_vi auto logLevel = getLogLevel(logSettingsPath); try { - auto sink = make_shared(logFilePath, 0, 0, false, 5); + auto sink = make_shared(logFilePath, 0, 0, false, LogSettings::retention); this->logger = make_shared(loggerName, sink); } catch (...) diff --git a/src/common/logger/logger.h b/src/common/logger/logger.h index 9a90d391c1..e95700e6ca 100644 --- a/src/common/logger/logger.h +++ b/src/common/logger/logger.h @@ -1,5 +1,6 @@ #pragma once #include +#include "logger_settings.h" class Logger { @@ -10,36 +11,42 @@ public: Logger(); Logger(std::string loggerName, std::wstring logFilePath, std::wstring_view logSettingsPath); + // log message should not be localized template void trace(const FormatString& fmt, const Args&... args) { this->logger->trace(fmt, args...); } + // log message should not be localized template void debug(const FormatString& fmt, const Args&... args) { this->logger->debug(fmt, args...); } + // log message should not be localized template void info(const FormatString& fmt, const Args&... args) { this->logger->info(fmt, args...); } + // log message should not be localized template void warn(const FormatString& fmt, const Args&... args) { this->logger->warn(fmt, args...); } + // log message should not be localized template void error(const FormatString& fmt, const Args&... args) { this->logger->error(fmt, args...); } + // log message should not be localized template void critical(const FormatString& fmt, const Args&... args) { diff --git a/src/common/logger/logger_settings.h b/src/common/logger/logger_settings.h index c4e071b183..dd131fc524 100644 --- a/src/common/logger/logger_settings.h +++ b/src/common/logger/logger_settings.h @@ -6,7 +6,11 @@ struct LogSettings // The following strings are not localizable inline const static std::wstring defaultLogLevel = L"warn"; inline const static std::wstring logLevelOption = L"logLevel"; - + inline const static std::string runnerLoggerName = "runner"; + inline const static std::wstring runnerLogPath = L"RunnerLogs\\runner-log.txt"; + inline const static std::string launcherLoggerName = "launcher"; + inline const static std::wstring launcherLogPath = L"LogsModuleInterface\\launcher-log.txt"; + inline const static int retention = 30; std::wstring logLevel; LogSettings(); }; diff --git a/src/modules/launcher/Microsoft.Launcher/dllmain.cpp b/src/modules/launcher/Microsoft.Launcher/dllmain.cpp index 2c5bfe1ad1..836206b32a 100644 --- a/src/modules/launcher/Microsoft.Launcher/dllmain.cpp +++ b/src/modules/launcher/Microsoft.Launcher/dllmain.cpp @@ -87,8 +87,8 @@ public: app_name = GET_RESOURCE_STRING(IDS_LAUNCHER_NAME); app_key = LauncherConstants::ModuleKey; std::filesystem::path logFilePath(PTSettingsHelper::get_module_save_folder_location(this->app_key)); - logFilePath.append("logging.txt"); - logger = std::make_shared("launcher", logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location()); + logFilePath.append(LogSettings::launcherLogPath); + logger = std::make_shared(LogSettings::launcherLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location()); logger->info("Launcher object is constructing"); init_settings(); diff --git a/src/runner/main.cpp b/src/runner/main.cpp index ebfe9347e4..aef500d230 100644 --- a/src/runner/main.cpp +++ b/src/runner/main.cpp @@ -296,8 +296,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine } std::filesystem::path logFilePath(PTSettingsHelper::get_root_save_folder_location()); - logFilePath = logFilePath.append(L"runner-logging.txt"); - logger = std::make_shared("runner", logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location()); + logFilePath = logFilePath.append(LogSettings::runnerLogPath); + logger = std::make_shared(LogSettings::runnerLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location()); int n_cmd_args = 0; LPWSTR* cmd_arg_list = CommandLineToArgvW(GetCommandLineW(), &n_cmd_args);