Adjustments for runner process logging (#8112)

This commit is contained in:
Mykhailo Pylyp
2020-11-18 20:25:20 +02:00
committed by GitHub
parent e2473b70ca
commit 53bbd08fd3
5 changed files with 17 additions and 7 deletions

View File

@@ -3,7 +3,6 @@
#include "pch.h" #include "pch.h"
#include "framework.h" #include "framework.h"
#include "logger.h" #include "logger.h"
#include "logger_settings.h"
#include <map> #include <map>
#include <spdlog/sinks/daily_file_sink.h> #include <spdlog/sinks/daily_file_sink.h>
#include <spdlog\sinks\stdout_color_sinks-inl.h> #include <spdlog\sinks\stdout_color_sinks-inl.h>
@@ -43,7 +42,7 @@ Logger::Logger(std::string loggerName, std::wstring logFilePath, std::wstring_vi
auto logLevel = getLogLevel(logSettingsPath); auto logLevel = getLogLevel(logSettingsPath);
try try
{ {
auto sink = make_shared<sinks::daily_file_sink_mt>(logFilePath, 0, 0, false, 5); auto sink = make_shared<sinks::daily_file_sink_mt>(logFilePath, 0, 0, false, LogSettings::retention);
this->logger = make_shared<spdlog::logger>(loggerName, sink); this->logger = make_shared<spdlog::logger>(loggerName, sink);
} }
catch (...) catch (...)

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include "logger_settings.h"
class Logger class Logger
{ {
@@ -10,36 +11,42 @@ public:
Logger(); Logger();
Logger(std::string loggerName, std::wstring logFilePath, std::wstring_view logSettingsPath); Logger(std::string loggerName, std::wstring logFilePath, std::wstring_view logSettingsPath);
// log message should not be localized
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
void trace(const FormatString& fmt, const Args&... args) void trace(const FormatString& fmt, const Args&... args)
{ {
this->logger->trace(fmt, args...); this->logger->trace(fmt, args...);
} }
// log message should not be localized
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
void debug(const FormatString& fmt, const Args&... args) void debug(const FormatString& fmt, const Args&... args)
{ {
this->logger->debug(fmt, args...); this->logger->debug(fmt, args...);
} }
// log message should not be localized
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
void info(const FormatString& fmt, const Args&... args) void info(const FormatString& fmt, const Args&... args)
{ {
this->logger->info(fmt, args...); this->logger->info(fmt, args...);
} }
// log message should not be localized
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
void warn(const FormatString& fmt, const Args&... args) void warn(const FormatString& fmt, const Args&... args)
{ {
this->logger->warn(fmt, args...); this->logger->warn(fmt, args...);
} }
// log message should not be localized
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
void error(const FormatString& fmt, const Args&... args) void error(const FormatString& fmt, const Args&... args)
{ {
this->logger->error(fmt, args...); this->logger->error(fmt, args...);
} }
// log message should not be localized
template<typename FormatString, typename... Args> template<typename FormatString, typename... Args>
void critical(const FormatString& fmt, const Args&... args) void critical(const FormatString& fmt, const Args&... args)
{ {

View File

@@ -6,7 +6,11 @@ struct LogSettings
// The following strings are not localizable // The following strings are not localizable
inline const static std::wstring defaultLogLevel = L"warn"; inline const static std::wstring defaultLogLevel = L"warn";
inline const static std::wstring logLevelOption = L"logLevel"; 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; std::wstring logLevel;
LogSettings(); LogSettings();
}; };

View File

@@ -87,8 +87,8 @@ public:
app_name = GET_RESOURCE_STRING(IDS_LAUNCHER_NAME); app_name = GET_RESOURCE_STRING(IDS_LAUNCHER_NAME);
app_key = LauncherConstants::ModuleKey; app_key = LauncherConstants::ModuleKey;
std::filesystem::path logFilePath(PTSettingsHelper::get_module_save_folder_location(this->app_key)); std::filesystem::path logFilePath(PTSettingsHelper::get_module_save_folder_location(this->app_key));
logFilePath.append("logging.txt"); logFilePath.append(LogSettings::launcherLogPath);
logger = std::make_shared<Logger>("launcher", logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location()); logger = std::make_shared<Logger>(LogSettings::launcherLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
logger->info("Launcher object is constructing"); logger->info("Launcher object is constructing");
init_settings(); init_settings();

View File

@@ -296,8 +296,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
} }
std::filesystem::path logFilePath(PTSettingsHelper::get_root_save_folder_location()); std::filesystem::path logFilePath(PTSettingsHelper::get_root_save_folder_location());
logFilePath = logFilePath.append(L"runner-logging.txt"); logFilePath = logFilePath.append(LogSettings::runnerLogPath);
logger = std::make_shared<Logger>("runner", logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location()); logger = std::make_shared<Logger>(LogSettings::runnerLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
int n_cmd_args = 0; int n_cmd_args = 0;
LPWSTR* cmd_arg_list = CommandLineToArgvW(GetCommandLineW(), &n_cmd_args); LPWSTR* cmd_arg_list = CommandLineToArgvW(GetCommandLineW(), &n_cmd_args);