Foundation
Loading...
Searching...
No Matches
Logging.hpp
Go to the documentation of this file.
1#pragma once
2#include <fmt/base.h>
3#include <fmt/format.h>
11// NOLINTBEGIN
12constexpr const char* format_as(LogLevel level)
13{
14 switch (level)
15 {
16 case LogDebug: return "\033[34mD";
17 case LogInfo: return "\033[37mI";
18 case LogError: return "\033[31mE";
19 case LogWarn: return "\033[33mW";
20 }
21}
22
23// NOLINTEND
24
25extern void Foundation_LogImpl(LogLevel level, const char* tag, std::string_view formatted);
26template<typename ...Args>
27void Foundation_Log(const char* tag, LogLevel level, fmt::format_string<Args...> format, Args&&... args)
28{
29 constexpr size_t kN = sizeof...(Args);
30 if constexpr (kN > 0)
31 {
32 Foundation_LogImpl(level, tag, fmt::format(format, std::forward<Args>(args)...));
33 } else
34 {
35 Foundation_LogImpl(level, tag, format.str.data());
36 }
37}
38
39#define LOG(TAG, LEVEL, FORMAT, ...) Foundation_Log(#TAG, LEVEL, FORMAT __VA_OPT__(,) __VA_ARGS__);
40
41#define CHECK(expr) if(!(expr)) { \
42 LOG(Core, LogError, "Check failed: " #expr); \
43 throw std::runtime_error( #expr ); \
44}
45
46#define CHECK_MSG(expr, format_str, ...) if(!(expr)) { \
47 LOG(Core, LogError, format_str __VA_OPT__(,) __VA_ARGS__); \
48 throw std::runtime_error( #expr ); \
49}
void Foundation_Log(const char *tag, LogLevel level, fmt::format_string< Args... > format, Args &&... args)
Definition Logging.hpp:27
constexpr const char * format_as(LogLevel level)
Definition Logging.hpp:12
LogLevel
Definition Logging.hpp:5
@ LogWarn
Definition Logging.hpp:8
@ LogDebug
Definition Logging.hpp:6
@ LogError
Definition Logging.hpp:9
@ LogInfo
Definition Logging.hpp:7
void Foundation_LogImpl(LogLevel level, const char *tag, std::string_view formatted)
Definition Logging.cpp:6