11#include "spdlog/common.h"
12#include "spdlog/sinks/basic_file_sink.h"
13#include "spdlog/sinks/stdout_color_sinks.h"
14#include "spdlog/async.h"
15#include <spdlog/spdlog.h>
31 std::set<std::string>::iterator
38 std::pair<std::set<std::string>::iterator,
bool> insertion =
EnabledLoggingKeys.insert(KeyName);
39 if (insertion.second) {
56 isKeyActive(
const std::set<std::string>::iterator &logginIterator) {
63 template<
typename... Args>
65 error(
const std::set<std::string>::iterator &logginIterator,
const std::string &format,
const Args &... args) {
67 log(
"error", format, args...);
71 template<
typename... Args>
73 error(
const std::string &format,
const Args &... args) {
74 log(
"error", format, args...);
77 template<
typename... Args>
79 info(
const std::set<std::string>::iterator &logginIterator,
const std::string &format,
const Args &... args) {
81 log(
"info", format, args...);
85 template<
typename... Args>
87 info(
const std::string &format,
const Args &... args) {
88 log(
"info", format, args...);
91 template<
typename... Args>
93 warn(
const std::set<std::string>::iterator &logginIterator,
const std::string &format,
const Args &... args) {
95 log(
"warn", format, args...);
99 template<
typename... Args>
101 warn(
const std::string &format,
const Args &... args) {
102 log(
"warn", format, args...);
105 template<
typename... Args>
107 critical(
const std::set<std::string>::iterator &logginIterator,
108 const std::string &format,
109 const Args &... args) {
111 log(
"critical", format, args...);
115 template<
typename... Args>
117 critical(
const std::string &format,
const Args &... args) {
118 log(
"critical", format, args...);
122 if (alsoSetFileLogger) {
129 if (alsoSetFileLogger) {
136 if (alsoSetFileLogger) {
143 if (alsoSetFileLogger) {
150 if (alsoSetFileLogger) {
162 char* envVarFileLoggingPath = std::getenv(
"AYONLOGGERFILEPOS");
164 if (envVarFileLoggingPath !=
nullptr) {
166 std::filesystem::absolute(std::string(envVarFileLoggingPath) +
"/logFile.json").
string());
170 char* envVarFileLogging = std::getenv(
"AYONLOGGERFILELOGGING");
172 if (envVarFileLogging !=
nullptr) {
173 switch (envVarFileLogging[1]) {
179 file_logger_ = spdlog::basic_logger_mt<spdlog::async_factory>(
182 "{\"timestamp\":\"%Y-%m-%d %H:%M:%S.%e\",\"level\":\"%l\",\"Thread "
183 "Id\":\"%t\",\"Process Id\":\"%P\",\"message\":\"%v\"}");
188 char* envVarLogLvl = std::getenv(
"AYONLOGGERLOGLVL");
190 if (envVarLogLvl !=
nullptr) {
191 switch (envVarLogLvl[0]) {
227 const char* envVarLoggingKeys = std::getenv(
"AYON_LOGGIN_LOGGIN_KEYS");
228 if (envVarLoggingKeys !=
nullptr) {
229 std::string envVarString(envVarLoggingKeys);
231 std::istringstream tokenStream(envVarString);
232 while (std::getline(tokenStream, token,
'/')) {
238 template<
typename... Args>
240 log(
const std::string &level,
const std::string &massage,
const Args &... args) {
242 std::string formatted_message = fmt::vformat(massage, fmt::make_format_args(args...));
245 file_logger_->log(spdlog::level::from_str(level), formatted_message);
247 console_logger_->log(spdlog::level::from_str(level), formatted_message);
Simple Logger Class that wraps around spdlog in order to expose easy logging functions AyonLogger::...
Definition: AyonLogger.h:23
std::shared_ptr< spdlog::logger > console_logger_
Definition: AyonLogger.h:249
void error(const std::string &format, const Args &... args)
Definition: AyonLogger.h:73
void LogLevlOff(const bool &alsoSetFileLogger=false)
Definition: AyonLogger.h:149
bool fileLoggerFilePathOverwrite
Definition: AyonLogger.h:252
void LogLevlInfo(const bool &alsoSetFileLogger=false)
Definition: AyonLogger.h:121
bool enableFileLogging
Definition: AyonLogger.h:251
std::set< std::string >::iterator key(const std::string &key)
Definition: AyonLogger.h:32
bool isKeyActive(const std::set< std::string >::iterator &logginIterator)
Definition: AyonLogger.h:56
void LogLevlCritical(const bool &alsoSetFileLogger=false)
Definition: AyonLogger.h:142
std::set< std::string > EnabledLoggingKeys
Definition: AyonLogger.h:254
void LogLevlWarn(const bool &alsoSetFileLogger=false)
Definition: AyonLogger.h:135
void error(const std::set< std::string >::iterator &logginIterator, const std::string &format, const Args &... args)
Definition: AyonLogger.h:65
void warn(const std::set< std::string >::iterator &logginIterator, const std::string &format, const Args &... args)
Definition: AyonLogger.h:93
AyonLogger(const std::string &filepath)
Definition: AyonLogger.h:157
std::shared_ptr< spdlog::logger > file_logger_
Definition: AyonLogger.h:250
void info(const std::string &format, const Args &... args)
Definition: AyonLogger.h:87
void critical(const std::string &format, const Args &... args)
Definition: AyonLogger.h:117
bool unregisterLoggingKey(const std::string &KeyName)
Definition: AyonLogger.h:46
void critical(const std::set< std::string >::iterator &logginIterator, const std::string &format, const Args &... args)
Definition: AyonLogger.h:107
bool regesterLoggingKey(const std::string &KeyName)
Definition: AyonLogger.h:37
std::string fileLoggerFilePath
Definition: AyonLogger.h:253
void LogLevlError(const bool &alsoSetFileLogger=false)
Definition: AyonLogger.h:128
void info(const std::set< std::string >::iterator &logginIterator, const std::string &format, const Args &... args)
Definition: AyonLogger.h:79
void warn(const std::string &format, const Args &... args)
Definition: AyonLogger.h:101
void log(const std::string &level, const std::string &massage, const Args &... args)
Definition: AyonLogger.h:240
static AyonLogger & getInstance(const std::string &filepath)
Definition: AyonLogger.h:26