114 template <
typename... Args>
115 void Debug(std::string_view format, Args&&... args) {
119 template <
typename... Args>
120 void Info(std::string_view format, Args&&... args) {
124 template <
typename... Args>
125 void Warning(std::string_view format, Args&&... args) {
129 template <
typename... Args>
130 void Error(std::string_view format, Args&&... args) {
134 template <
typename... Args>
135 void Fatal(std::string_view format, Args&&... args) {
140 void Debug(std::string_view message) {
143 void Info(std::string_view message) {
149 void Error(std::string_view message) {
152 void Fatal(std::string_view message) {
160 template <
typename... Args>
161 void Log(
LogLevel level, std::string_view format, Args&&... args) {
162 if (level < m_minLevel) {
166 const std::string message = Format(format, std::forward<Args>(args)...);
167 LogMessage(level, message);
170 void Log(
LogLevel level, std::string_view message) {
171 if (level < m_minLevel) {
174 LogMessage(level, std::string(message));
177 void LogMessage(
LogLevel level,
const std::string& message);
180 template <
typename... Args>
181 std::string Format(std::string_view format, Args&&... args) {
182 std::ostringstream oss;
183 FormatImpl(oss, format, std::forward<Args>(args)...);
187 template <
typename T,
typename... Args>
188 void FormatImpl(std::ostringstream& oss, std::string_view format, T&& first, Args&&... rest) {
189 const size_t pos = format.find(
"{}");
190 if (pos != std::string_view::npos) {
191 oss << format.substr(0, pos) << std::forward<T>(first);
192 FormatImpl(oss, format.substr(pos + 2), std::forward<Args>(rest)...);
198 void FormatImpl(std::ostringstream& oss, std::string_view format) {
202 std::string GetTimestamp()
const;
203 std::string LevelToString(
LogLevel level)
const;
204 const char* LevelToColor(
LogLevel level)
const;
207 bool m_consoleOutput =
true;
208 bool m_fileOutput =
false;
209 std::filesystem::path m_logFilePath;
210 std::ofstream m_logFile;
211 mutable std::mutex m_mutex;
217#define LOG_DEBUG(...) MetaImGUI::Logger::Instance().Debug(__VA_ARGS__)
218#define LOG_INFO(...) MetaImGUI::Logger::Instance().Info(__VA_ARGS__)
219#define LOG_WARNING(...) MetaImGUI::Logger::Instance().Warning(__VA_ARGS__)
220#define LOG_ERROR(...) MetaImGUI::Logger::Instance().Error(__VA_ARGS__)
221#define LOG_FATAL(...) MetaImGUI::Logger::Instance().Fatal(__VA_ARGS__)