Foundation
Loading...
Searching...
No Matches
Logging.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <exception>
5
6#include <spdlog/spdlog.h>
7#include <spdlog/sinks/dist_sink.h>
8#include <spdlog/sinks/ringbuffer_sink.h>
9
10namespace Foundation::Core {
11 const size_t kMaxBacktraceLogMessages = 1000;
12 extern std::shared_ptr<spdlog::sinks::dist_sink_mt> getLoggingSink();
13 extern std::shared_ptr<spdlog::sinks::ringbuffer_sink_mt> getBacktraceSink();
14 extern spdlog::logger* getLogger(const char* name);
15}
16
17#define LOG_GET_GLOBAL_SINK() \
18 Foundation::Core::getLoggingSink()
19
20#define LOG_GET_LOGGER(TAG) \
21 Foundation::Core::getLogger(#TAG)
22
23#define LOG_RUNTIME(TAG, LEVEL, ...) \
24 SPDLOG_LOGGER_CALL(LOG_GET_LOGGER(TAG), spdlog::level::LEVEL __VA_OPT__(,) __VA_ARGS__)
25
26#define CHECK(expr) if(!(expr)) { \
27 LOG_RUNTIME(Core, err, "Check failed: {}", #expr); \
28 throw std::runtime_error( #expr ); \
29}
30
31#define CHECK_MSG(expr, format_str, ...) if(!(expr)) { \
32 std::string __message = fmt::format(format_str __VA_OPT__(,) __VA_ARGS__); \
33 LOG_RUNTIME(Core, err, __message); \
34 throw std::runtime_error(__message); \
35}
Allocators, Data Structures and introspection implementations.
Definition Allocator.hpp:5
spdlog::logger * getLogger(const char *name)
Definition Logging.cpp:36
const size_t kMaxBacktraceLogMessages
Definition Logging.hpp:11
std::shared_ptr< spdlog::sinks::dist_sink_mt > getLoggingSink()
Definition Logging.cpp:15
std::shared_ptr< spdlog::sinks::ringbuffer_sink_mt > getBacktraceSink()
Definition Logging.cpp:29