QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
MemoryLogSink.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <spdlog/sinks/base_sink.h>
9
10#include <chrono>
11#include <cstddef>
12#include <cstdint>
13#include <deque>
14#include <mutex>
15#include <string>
16#include <vector>
17
18namespace Quasar
19{
21 enum class LogLevel : std::uint8_t
22 {
29 };
30
33 {
35 std::chrono::system_clock::time_point Time;
36 std::string LoggerName;
37 std::string Text;
38 };
39
44 class MemoryLogSink final : public spdlog::sinks::base_sink<std::mutex>
45 {
46 public:
48 explicit MemoryLogSink(std::size_t capacity);
49
51 std::vector<LogMessage> GetMessages() const;
52
54 void Clear();
55
57 std::size_t GetCapacity() const { return m_Capacity; }
58
59 protected:
61 void sink_it_(const spdlog::details::log_msg& message) override;
62
64 void flush_() override {}
65
66 private:
67 const std::size_t m_Capacity;
68 mutable std::mutex m_MessagesMutex;
69 std::deque<LogMessage> m_Messages;
70 };
71}
void Clear()
Removes every kept message.
std::vector< LogMessage > GetMessages() const
Returns a copy of the kept messages, from the oldest to the most recent.
void flush_() override
Does nothing: the messages are already in memory.
Definition MemoryLogSink.h:64
void sink_it_(const spdlog::details::log_msg &message) override
Keeps a new message. Called by spdlog for each message written to a logger that uses this sink.
MemoryLogSink(std::size_t capacity)
Creates a sink that keeps at most capacity messages. A capacity of 0 keeps one message.
std::size_t GetCapacity() const
Returns the maximum number of messages the sink keeps.
Definition MemoryLogSink.h:57
Contains all the engine code.
LogLevel
Severity of a log message.
Definition MemoryLogSink.h:22
@ Warning
Something unexpected that does not stop the program.
Definition MemoryLogSink.h:26
@ Critical
Something failed and the program cannot continue.
Definition MemoryLogSink.h:28
@ Info
Normal information.
Definition MemoryLogSink.h:25
@ Error
Something failed.
Definition MemoryLogSink.h:27
@ Debug
Information useful while debugging.
Definition MemoryLogSink.h:24
@ Trace
Detailed information, only written in Debug builds.
Definition MemoryLogSink.h:23
A log message kept by MemoryLogSink.
Definition MemoryLogSink.h:33
LogLevel Level
Severity of the message.
Definition MemoryLogSink.h:34
std::string LoggerName
Name of the logger, "ENGINE" or "APP".
Definition MemoryLogSink.h:36
std::chrono::system_clock::time_point Time
Time when the message was written.
Definition MemoryLogSink.h:35
std::string Text
Text of the message, without the time or the level.
Definition MemoryLogSink.h:37