QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
Log.h
Go to the documentation of this file.
1#pragma once
2
12
14
15#include <spdlog/spdlog.h>
16
17#include <cstddef>
18#include <memory>
19
20namespace Quasar
21{
22 class MemoryLogSink;
23
29 class Log
30 {
31 public:
33 static void Init();
34
36 static void Shutdown();
37
42 static spdlog::logger& Engine() { return s_EngineLogger ? *s_EngineLogger : GetFallbackEngineLogger(); }
43
48 static spdlog::logger& App() { return s_AppLogger ? *s_AppLogger : GetFallbackAppLogger(); }
49
53 static std::shared_ptr<MemoryLogSink> GetMemorySink() { return s_MemorySink; }
54
56 static constexpr std::size_t MemoryCapacity = 1000;
57
58 private:
59 static spdlog::logger& GetFallbackEngineLogger();
60 static spdlog::logger& GetFallbackAppLogger();
61
62 static std::shared_ptr<spdlog::logger> s_EngineLogger;
63 static std::shared_ptr<spdlog::logger> s_AppLogger;
64 static std::shared_ptr<MemoryLogSink> s_MemorySink;
65 };
66}
67
71
75#ifdef QUASAR_DEBUG
76#define QUASAR_ENGINE_TRACE(...) ::Quasar::Log::Engine().trace(__VA_ARGS__)
77#define QUASAR_TRACE(...) ::Quasar::Log::App().trace(__VA_ARGS__)
78#else
79#define QUASAR_ENGINE_TRACE(...) \
80 do \
81 { \
82 if constexpr (false) \
83 { \
84 ::Quasar::Log::Engine().trace(__VA_ARGS__); \
85 } \
86 } while (false)
87#define QUASAR_TRACE(...) \
88 do \
89 { \
90 if constexpr (false) \
91 { \
92 ::Quasar::Log::App().trace(__VA_ARGS__); \
93 } \
94 } while (false)
95#endif
96
99
102
105
106#define QUASAR_ENGINE_INFO(...) ::Quasar::Log::Engine().info(__VA_ARGS__)
107#define QUASAR_ENGINE_WARN(...) ::Quasar::Log::Engine().warn(__VA_ARGS__)
108#define QUASAR_ENGINE_ERROR(...) ::Quasar::Log::Engine().error(__VA_ARGS__)
109
112
115
118
119#define QUASAR_INFO(...) ::Quasar::Log::App().info(__VA_ARGS__)
120#define QUASAR_WARN(...) ::Quasar::Log::App().warn(__VA_ARGS__)
121#define QUASAR_ERROR(...) ::Quasar::Log::App().error(__VA_ARGS__)
Detects the platform and the build type at compile time.
The loggers for the engine and the application.
Definition Log.h:30
static constexpr std::size_t MemoryCapacity
Number of messages kept by the memory sink.
Definition Log.h:56
static void Init()
Creates the loggers. Calling it again does nothing.
static spdlog::logger & Engine()
Returns the logger for engine messages.
Definition Log.h:42
static std::shared_ptr< MemoryLogSink > GetMemorySink()
Returns the sink that keeps the most recent messages of both loggers, for the editor console.
Definition Log.h:53
static void Shutdown()
Destroys the loggers. Until Init() is called again, messages go to the fallback loggers.
static spdlog::logger & App()
Returns the logger for application messages.
Definition Log.h:48
Log sink that keeps the most recent messages in memory, so that the console can display them.
Definition MemoryLogSink.h:45
Contains all the engine code.