WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
Logger.h
Go to the documentation of this file.
1#pragma once
2
3#include <sstream>
4#include <string>
5
6#include "Container.h"
7#include "LogOutput.h"
8
9#define LOGGER WMVLog::Logger::instance()
10#define LOG_INFO LOGGER(WMVLog::Logger::INFO_LOG)
11#define LOG_ERROR LOGGER(WMVLog::Logger::ERROR_LOG)
12#define LOG_WARNING LOGGER(WMVLog::Logger::WARNING_LOG)
13#define LOG_FATAL LOGGER(WMVLog::Logger::FATAL_LOG)
14
15namespace WMVLog
16{
17 class Logger;
18
23 {
24 public:
25 LogStream(Logger& logger, int type);
26 ~LogStream();
27
28 LogStream(const LogStream&) = delete;
29 LogStream& operator=(const LogStream&) = delete;
30 LogStream(LogStream&& other) noexcept;
31
32 template <typename T>
33 LogStream& operator<<(const T& value)
34 {
35 if (m_active)
36 m_stream << value;
37 return *this;
38 }
39
40 // Overload for std::wstring
41 LogStream& operator<<(const std::wstring& value);
42
43 // Overload for const wchar_t*
44 LogStream& operator<<(const wchar_t* value);
45
46 private:
48 int m_type;
49 std::ostringstream m_stream;
51 };
52
57 class Logger : public Container<LogOutput>
58 {
59 public:
67
68 static Logger &instance()
69 {
70 if (Logger::m_instance == nullptr)
72
73 return *m_instance;
74 }
75
77 static void init();
78
80 void dispatchLog(int type, const std::string& msg);
81
83 static std::string formatLog(int type, const std::string& msg);
84
87
88 private:
89 Logger();
90 Logger(const Logger&) = delete;
91 Logger& operator=(const Logger&) = delete;
92
94 };
95}
Generic typed container that manages a set of child Component pointers.
Definition Container.h:13
RAII stream object that collects log output and dispatches it on destruction.
Definition Logger.h:23
Logger * m_logger
Definition Logger.h:47
LogStream & operator<<(const T &value)
Definition Logger.h:33
std::ostringstream m_stream
Definition Logger.h:49
LogStream(const LogStream &)=delete
LogStream & operator=(const LogStream &)=delete
Singleton logging facility that dispatches formatted messages to LogOutput sinks.
Definition Logger.h:58
static Logger * m_instance
Definition Logger.h:93
Logger(const Logger &)=delete
LogStream operator()(Logger::LogType type)
Create a LogStream for the given severity level.
Definition Logger.cpp:63
void dispatchLog(int type, const std::string &msg)
Send a pre-formatted message to all registered outputs.
Definition Logger.cpp:24
static std::string formatLog(int type, const std::string &msg)
Format a log message with a severity prefix and timestamp.
Definition Logger.cpp:31
static Logger & instance()
Definition Logger.h:68
static void init()
Initialise the logging subsystem (creates console and file outputs).
Definition Logger.cpp:20
Logger & operator=(const Logger &)=delete