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>
56 void OnSettingsLoaded()
override;
59 void OnSettingChanged(
const std::shared_ptr<const CSetting>& setting)
override;
61 void Initialize(
const std::string& path);
62 void UnregisterFromSettings();
65 void SetLogLevel(
int level);
66 int GetLogLevel() {
return m_logLevel; }
67 bool IsLogLevelLogged(
int loglevel);
69 bool CanLogComponent(uint32_t component)
const;
70 static void SettingOptionsLoggingComponentsFiller(
const std::shared_ptr<const CSetting>& setting,
71 std::vector<IntegerSettingOption>& list,
75 Logger GetLogger(
const std::string& loggerName);
77 template<
typename... Args>
78 static inline void Log(
int level,
const std::string_view& format, Args&&... args)
80 Log(MapLogLevel(level), format, std::forward<Args>(args)...);
83 template<
typename... Args>
84 static inline void Log(
int level,
86 const std::string_view& format,
89 if (!GetInstance().CanLogComponent(component))
92 Log(level, format, std::forward<Args>(args)...);
95 template<
typename... Args>
96 static inline void Log(spdlog::level::level_enum level,
97 const std::string_view& format,
100 GetInstance().FormatAndLogInternal(level, format, std::forward<Args>(args)...);
103 template<
typename... Args>
104 static inline void Log(spdlog::level::level_enum level,
106 const std::string_view& format,
109 if (!GetInstance().CanLogComponent(component))
112 Log(level, format, std::forward<Args>(args)...);
115 #define LogF(level, format, ...) Log((level), ("{}: " format), __FUNCTION__, ##__VA_ARGS__) 116 #define LogFC(level, component, format, ...) \ 117 Log((level), (component), ("{}: " format), __FUNCTION__, ##__VA_ARGS__) 120 static CLog& GetInstance();
122 static spdlog::level::level_enum MapLogLevel(
int level);
124 template<
typename... Args>
125 inline void FormatAndLogInternal(spdlog::level::level_enum level,
126 const std::string_view& format,
129 auto message = fmt::format(format, std::forward<Args>(args)...);
132 FormatLineBreaks(message);
134 m_defaultLogger->log(level, message);
137 Logger CreateLogger(
const std::string& loggerName);
139 void SetComponentLogLevel(
const std::vector<CVariant>& components);
141 void FormatLineBreaks(std::string& message);
143 std::unique_ptr<IPlatformLog> m_platform;
144 std::shared_ptr<spdlog::sinks::dist_sink<std::mutex>> m_sinks;
145 Logger m_defaultLogger;
147 std::shared_ptr<spdlog::sinks::sink> m_fileSink;
151 bool m_componentLogEnabled;
152 uint32_t m_componentLogLevels;
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