File LogWriter.hpp¶
File List > Engine > include > Logging > LogWriter.hpp
Go to the documentation of this file
#ifndef ENGINE_LOGGING_LOGWRITER_HPP_
#define ENGINE_LOGGING_LOGWRITER_HPP_
#include "Logging/LogConfig.hpp"
#include <condition_variable>
#include <cstddef>
#include <deque>
#include <mutex>
#include <string>
#if !defined(__EMSCRIPTEN__)
#include <thread>
#endif
namespace Engine {
class LogWriter {
public:
static constexpr std::size_t Capacity = 1024;
LogWriter();
~LogWriter();
LogWriter(const LogWriter&) = delete;
LogWriter& operator=(const LogWriter&) = delete;
void Enqueue(LogLevel level, std::string message);
void Shutdown();
private:
enum class State { Running, Stopped };
struct Record {
LogLevel level;
std::string message;
};
void Run();
std::mutex m_Mutex;
std::condition_variable m_Cv;
std::deque<Record> m_Queue;
#if !defined(__EMSCRIPTEN__)
std::thread m_Thread;
#endif
std::size_t m_Dropped = 0;
bool m_Stopping = false;
bool m_Started = false;
bool m_ShutdownCalled = false;
State m_State = State::Running;
};
void SetTerminalLogToStderr();
void WriteLogLine(LogLevel level, const std::string& message);
void EnqueueLog(LogLevel level, std::string message);
void ShutdownLogging();
} // namespace Engine
#endif // ENGINE_LOGGING_LOGWRITER_HPP_