2020-11-18 11:15:14 +01:00
|
|
|
#pragma once
|
|
|
|
#include <spdlog/spdlog.h>
|
2020-11-18 19:25:20 +01:00
|
|
|
#include "logger_settings.h"
|
2020-11-18 11:15:14 +01:00
|
|
|
|
|
|
|
class Logger
|
|
|
|
{
|
|
|
|
private:
|
2020-11-30 15:16:49 +01:00
|
|
|
inline const static std::wstring logFailedShown = L"logFailedShown";
|
|
|
|
static std::shared_ptr<spdlog::logger> logger;
|
|
|
|
static bool wasLogFailedShown();
|
2020-11-18 11:15:14 +01:00
|
|
|
|
|
|
|
public:
|
2020-11-30 15:16:49 +01:00
|
|
|
Logger() = delete;
|
|
|
|
|
|
|
|
static void init(std::string loggerName, std::wstring logFilePath, std::wstring_view logSettingsPath);
|
2021-11-09 20:48:07 +01:00
|
|
|
static void init(std::vector<spdlog::sink_ptr> sinks);
|
2020-11-18 11:15:14 +01:00
|
|
|
|
2020-11-18 19:25:20 +01:00
|
|
|
// log message should not be localized
|
2020-11-18 11:15:14 +01:00
|
|
|
template<typename FormatString, typename... Args>
|
2020-11-30 15:16:49 +01:00
|
|
|
static void trace(const FormatString& fmt, const Args&... args)
|
2020-11-18 11:15:14 +01:00
|
|
|
{
|
2020-11-30 15:16:49 +01:00
|
|
|
logger->trace(fmt, args...);
|
2020-11-18 11:15:14 +01:00
|
|
|
}
|
|
|
|
|
2020-11-18 19:25:20 +01:00
|
|
|
// log message should not be localized
|
2020-11-18 11:15:14 +01:00
|
|
|
template<typename FormatString, typename... Args>
|
2020-11-30 15:16:49 +01:00
|
|
|
static void debug(const FormatString& fmt, const Args&... args)
|
2020-11-18 11:15:14 +01:00
|
|
|
{
|
2020-11-30 15:16:49 +01:00
|
|
|
logger->debug(fmt, args...);
|
2020-11-18 11:15:14 +01:00
|
|
|
}
|
|
|
|
|
2020-11-18 19:25:20 +01:00
|
|
|
// log message should not be localized
|
2020-11-18 11:15:14 +01:00
|
|
|
template<typename FormatString, typename... Args>
|
2020-11-30 15:16:49 +01:00
|
|
|
static void info(const FormatString& fmt, const Args&... args)
|
2020-11-18 11:15:14 +01:00
|
|
|
{
|
2020-11-30 15:16:49 +01:00
|
|
|
logger->info(fmt, args...);
|
2020-11-18 11:15:14 +01:00
|
|
|
}
|
|
|
|
|
2020-11-18 19:25:20 +01:00
|
|
|
// log message should not be localized
|
2020-11-18 11:15:14 +01:00
|
|
|
template<typename FormatString, typename... Args>
|
2020-11-30 15:16:49 +01:00
|
|
|
static void warn(const FormatString& fmt, const Args&... args)
|
2020-11-18 11:15:14 +01:00
|
|
|
{
|
2020-11-30 15:16:49 +01:00
|
|
|
logger->warn(fmt, args...);
|
2020-11-18 11:15:14 +01:00
|
|
|
}
|
|
|
|
|
2020-11-18 19:25:20 +01:00
|
|
|
// log message should not be localized
|
2020-11-18 11:15:14 +01:00
|
|
|
template<typename FormatString, typename... Args>
|
2020-11-30 15:16:49 +01:00
|
|
|
static void error(const FormatString& fmt, const Args&... args)
|
2020-11-18 11:15:14 +01:00
|
|
|
{
|
2020-11-30 15:16:49 +01:00
|
|
|
logger->error(fmt, args...);
|
2020-11-18 11:15:14 +01:00
|
|
|
}
|
|
|
|
|
2020-11-18 19:25:20 +01:00
|
|
|
// log message should not be localized
|
2020-11-18 11:15:14 +01:00
|
|
|
template<typename FormatString, typename... Args>
|
2020-11-30 15:16:49 +01:00
|
|
|
static void critical(const FormatString& fmt, const Args&... args)
|
2020-11-18 11:15:14 +01:00
|
|
|
{
|
2020-11-30 15:16:49 +01:00
|
|
|
logger->critical(fmt, args...);
|
2020-11-18 11:15:14 +01:00
|
|
|
}
|
2021-04-26 21:01:38 +02:00
|
|
|
|
|
|
|
static void flush()
|
|
|
|
{
|
|
|
|
logger->flush();
|
|
|
|
}
|
2020-11-18 11:15:14 +01:00
|
|
|
};
|