Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LOG.hxx
Go to the documentation of this file.
1 #ifndef LOG_HXX_
2 #define LOG_HXX_
3 
4 #include <string>
5 #include "Exception.hxx"
6 
7 #include <iostream>
8 #include <chrono>
9 #include <ctime>
10 #include <fstream>
11 #include <sstream>
12 #include <SDL.h>
13 #include <algorithm>
14 #include <mutex>
15 
16 #include "Meta.hxx"
17 
18 using std::string;
19 using std::stringstream;
20 using Mutex = std::mutex;
21 using LockGuard = std::lock_guard<Mutex>;
22 
23 enum LogType
24 {
25  LOG_INFO = 0,
30 };
31 
32 class LOG
33 {
34 
35  /* Mutex */
37 
38  static constexpr const char *LOG_PREFIX_COLORED[] = {
39  " - \x1B[38;5;39m\x1B[1m[INFO]\x1B[0m - ", " - \x1B[38;5;57m\x1B[1m[DEBUG]\x1B[0m - ",
40  " - \x1B[38;5;214m\x1B[1m[WARNING]\x1B[0m - ", " - \x1B[38;5;196m\x1B[1m[ERROR]\x1B[0m - ",
41  " - \x1B[38;5;124m\x1B[1m[FATAL]\x1B[0m - ",
42  };
43 
44  static constexpr const char *LOG_PREFIX[] = {
45  " - [INFO] - ", " - [DEBUG] - ", " - [WARNING] - ", " - [ERROR] - ", " - [FATAL] - ",
46  };
47 
48 public:
49  /* 1 MB */
51 
55  LOG(LogType type);
56 
60  ~LOG();
61 
66  template <class Object> LOG &operator<<(const Object &msg);
67 
68 private:
70  std::ostringstream m_Logger;
71 
75  const std::string getTimeStamp();
76 
81  void writeErrorLog(const std::string &errorMessage) const;
82 };
83 
84 #include "LOG.inl.hxx"
85 
86 #undef _CRT_SECURE_NO_WARNINGS
87 
88 #endif
Constant
Constant::value returns the value.
LOG::getTimeStamp
const std::string getTimeStamp()
Gets formatted TimeStamp.
Definition: LOG.cxx:41
LOG
Definition: LOG.hxx:32
LockGuard
std::lock_guard< Mutex > LockGuard
Definition: LOG.hxx:21
LOG_FATAL
@ LOG_FATAL
Definition: LOG.hxx:29
LOG_INFO
@ LOG_INFO
Definition: LOG.hxx:25
LOG::StreamMutex
static Mutex StreamMutex
Definition: LOG.hxx:36
LOG::LOG_PREFIX
static constexpr const char * LOG_PREFIX[]
Definition: LOG.hxx:44
LOG::writeErrorLog
void writeErrorLog(const std::string &errorMessage) const
Write log message to error.log file.
Definition: LOG.cxx:49
LOG::LOG
LOG(LogType type)
Create a Logger.
Definition: LOG.cxx:12
LOG_ERROR
@ LOG_ERROR
Definition: LOG.hxx:28
Mutex
std::mutex Mutex
Definition: MessageQueue.hxx:12
LOG_DEBUG
@ LOG_DEBUG
Definition: LOG.hxx:26
LogType
LogType
Definition: LOG.hxx:23
LOG::LOG_PREFIX_COLORED
static constexpr const char * LOG_PREFIX_COLORED[]
Definition: LOG.hxx:38
LOG::m_LogType
LogType m_LogType
Definition: LOG.hxx:69
Meta.hxx
LOG.inl.hxx
LOG::~LOG
~LOG()
Destroy a Logger.
Definition: LOG.cxx:14
LOG::m_Logger
std::ostringstream m_Logger
Definition: LOG.hxx:70
Exception.hxx
LOG::operator<<
LOG & operator<<(const Object &msg)
Log a message.
Definition: LOG.inl.hxx:2
string
std::string string
Definition: AudioConfig.hxx:14
LOG_WARNING
@ LOG_WARNING
Definition: LOG.hxx:27