13 #include <string_view> 14 #define SPDLOG_LEVEL_NAMES \ 16 std::string_view{"TRACE"}, \ 17 std::string_view{"DEBUG"}, \ 18 std::string_view{"INFO"}, \ 19 std::string_view{"WARNING"}, \ 20 std::string_view{"ERROR"}, \ 21 std::string_view{"FATAL"}, \ 22 std::string_view{"OFF"} \ 26 #include "commons/ilog.h" 27 #include "settings/lib/ISettingCallback.h" 28 #include "settings/lib/ISettingsHandler.h" 29 #include "settings/lib/SettingDefinitions.h" 30 #include "utils/IPlatformLog.h" 31 #include "utils/logtypes.h" 36 #include <spdlog/spdlog.h> 44 template<
typename Mutex>
49 #if FMT_VERSION >= 100000 50 using fmt::enums::format_as;
54 template<
typename T,
typename Char>
55 struct formatter<
std::atomic<T>, Char> : formatter<T, Char>
68 void OnSettingsLoaded()
override;
71 void OnSettingChanged(
const std::shared_ptr<const CSetting>& setting)
override;
73 void Initialize(
const std::string& path);
74 void UnregisterFromSettings();
77 void SetLogLevel(
int level);
78 int GetLogLevel() {
return m_logLevel; }
79 bool IsLogLevelLogged(
int loglevel);
81 bool CanLogComponent(uint32_t component)
const;
82 static void SettingOptionsLoggingComponentsFiller(
const std::shared_ptr<const CSetting>& setting,
83 std::vector<IntegerSettingOption>& list,
87 Logger GetLogger(
const std::string& loggerName);
89 template<
typename... Args>
90 static inline void Log(
int level,
const std::string_view& format, Args&&... args)
92 Log(MapLogLevel(level), format, std::forward<Args>(args)...);
95 template<
typename... Args>
96 static inline void Log(
int level,
98 const std::string_view& format,
101 if (!GetInstance().CanLogComponent(component))
104 Log(level, format, std::forward<Args>(args)...);
107 template<
typename... Args>
108 static inline void Log(spdlog::level::level_enum level,
109 const std::string_view& format,
112 GetInstance().FormatAndLogInternal(level, format, std::forward<Args>(args)...);
115 template<
typename... Args>
116 static inline void Log(spdlog::level::level_enum level,
118 const std::string_view& format,
121 if (!GetInstance().CanLogComponent(component))
124 Log(level, format, std::forward<Args>(args)...);
127 #define LogF(level, format, ...) Log((level), ("{}: " format), __FUNCTION__, ##__VA_ARGS__) 128 #define LogFC(level, component, format, ...) \ 129 Log((level), (component), ("{}: " format), __FUNCTION__, ##__VA_ARGS__) 132 static CLog& GetInstance();
134 static spdlog::level::level_enum MapLogLevel(
int level);
136 template<
typename... Args>
137 inline void FormatAndLogInternal(spdlog::level::level_enum level,
138 const std::string_view& format,
141 auto message = fmt::format(format, std::forward<Args>(args)...);
144 FormatLineBreaks(message);
146 m_defaultLogger->log(level, message);
149 Logger CreateLogger(
const std::string& loggerName);
151 void SetComponentLogLevel(
const std::vector<CVariant>& components);
153 void FormatLineBreaks(std::string& message);
155 std::unique_ptr<IPlatformLog> m_platform;
156 std::shared_ptr<spdlog::sinks::dist_sink<std::mutex>> m_sinks;
157 Logger m_defaultLogger;
159 std::shared_ptr<spdlog::sinks::sink> m_fileSink;
163 bool m_componentLogEnabled =
false;
164 uint32_t m_componentLogLevels = 0;
Definition: ISettingCallback.h:16
Definition: IPlatformLog.h:21
Interface defining methods being called by the settings system if an action is performed on multiple/...
Definition: ISettingsHandler.h:16