SA_Logger
Sapphire's Suite's C++ Logger.
Loading...
Searching...
No Matches
LoggerThread.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Sapphire's Suite. All Rights Reserved.
2
3#pragma once
4
5#ifndef SAPPHIRE_LOGGER_LOGGER_THREAD_GUARD
6#define SAPPHIRE_LOGGER_LOGGER_THREAD_GUARD
7
9
11
12#include <mutex>
13#include <thread>
14
24namespace SA
25{
32 class LoggerThread : public LoggerBase
33 {
38 std::atomic<uint32_t> mFrameNum = 0u;
39
40 //{ Thread
41
43 std::thread mThread;
44
46 std::atomic<bool> mIsRunning = true;
47
49 RingBuffer<SA::Log> mRingBuffer;
50
51 void ThreadLoop();
52
53 //}
54
55 //{ Streams
56
58 std::mutex mStreamMutex;
59
60 void ProcessLog(const SA::Log& _log, bool _bForce = false) override final;
61
62 void RegisterStream(ALogStream* _stream) override final;
63 bool UnregisterStream(ALogStream* _stream) override final;
64
65 //}
66
67 public:
69 LoggerThread(uint32_t _ringBufferSize = 32) noexcept;
70
76
77 void Log(SA::Log _log) override final;
78
79 //{ Streams
80
81 void ClearStreams(bool _bFlush = true) override final;
82
83
84 void Flush() override final;
85
86
87 void EnableLogLevel(LogLevel _level) override final;
88
89 void DisableLogLevel(LogLevel _level) override final;
90
91
92 void EnableLogChannel(const std::wstring& _channel) override final;
93
94 void DisableLogChannel(const std::wstring& _channel) override final;
95
96 //}
97
98
99 //{ Frame Num
100
102 void IncrementFrameNum() override final;
103
105 uint32_t GetFrameNum() const override final;
106 //}
107 };
108}
109
110
113#endif // GUARD
LogLevel
All levels of logging.
Definition LogLevel.hpp:26
Logger base class implementation.
Thread-safe RingBuffer class implementation. Multiple producers, single consumer implementation.
Abstract log stream class.
Definition ALogStream.hpp:27
Log type implementation.
Definition Log.hpp:25
Logger base class implementation.
Definition LoggerBase.hpp:29
Multithread logger class.
Definition LoggerThread.hpp:33
void EnableLogLevel(LogLevel _level) override final
Enable LogLevel for all registered streams.
uint32_t GetFrameNum() const override final
Get current registered frame number.
LoggerThread(uint32_t _ringBufferSize=32) noexcept
Default Constructor.
void Flush() override final
Force logger to flush all streams.
void ClearStreams(bool _bFlush=true) override final
void EnableLogChannel(const std::wstring &_channel) override final
Enable LogChannel for all registered streams.
void IncrementFrameNum() override final
Increment current registered frame number.
void DisableLogChannel(const std::wstring &_channel) override final
Disable LogChannel for all registered streams.
void DisableLogLevel(LogLevel _level) override final
Disable LogLevel for all registered streams.
RingBuffer class implementation.
Definition RingBuffer.hpp:31