YggdrasilWM  0.1.1
A tiny window manager coded in C++
Logger.hpp
Go to the documentation of this file.
1 
31 #ifndef WINDOWMANAGER_LOGGER_H
32 #define WINDOWMANAGER_LOGGER_H
33 #include <string>
34 #include <iostream>
35 #include <iomanip>
36 #include <ctime>
37 #include <sstream>
38 #include <fstream>
39 #include <memory>
40 #include <mutex>
41 
48 enum LogLevel {
52 };
60 class Logger {
61 public:
62  Logger(const Logger&) = delete;
63  Logger& operator=(const Logger&) = delete;
71  static void Create(const std::string& logFile, LogLevel logLevel);
79  static void Create(std::ostream& output, LogLevel logLevel);
85  static Logger* GetInstance();
91  static void Destroy();
97  virtual ~Logger();
108  virtual void Log(const std::string& message, LogLevel level) const;
109 
110 private:
118  Logger(const std::string& logFile, LogLevel logLevel);
126  Logger(std::ostream& output, LogLevel logLevel);
133  static std::string GetLogLevel(LogLevel level);
140  static std::string GetTime();
147  static Logger* instance_;
148  std::ostream* logStream_;
150 };
151 #endif //WINDOWMANAGER_LOGGER_H
LogLevel
Log levels L_INFO: Informational messages L_WARNING: Warning messages L_ERROR: Error messages.
Definition: Logger.hpp:48
@ L_ERROR
Definition: Logger.hpp:51
@ L_WARNING
Definition: Logger.hpp:50
@ L_INFO
Definition: Logger.hpp:49
Logger class This class is responsible for logging. It can be created with a file name or an ostream....
Definition: Logger.hpp:60
static std::string GetTime()
Get the current time.
Definition: Logger.cpp:79
LogLevel logLevel_
Definition: Logger.hpp:149
Logger & operator=(const Logger &)=delete
virtual void Log(const std::string &message, LogLevel level) const
Log a message This method logs a message to the log file or stream. The message is only logged if the...
Definition: Logger.cpp:73
static Logger * instance_
Definition: Logger.hpp:147
static void Create(const std::string &logFile, LogLevel logLevel)
Definition: Logger.cpp:31
bool streamIsFile_
Definition: Logger.hpp:146
static std::string GetLogLevel(LogLevel level)
Get the log level as a string.
Definition: Logger.cpp:86
std::ostream * logStream_
Definition: Logger.hpp:148
virtual ~Logger()
Destroy the Logger:: Logger object closes the log file if it was opened. The destructor is virtual to...
Definition: Logger.cpp:62
static void Destroy()
Destroy the Logger:: Logger object closes the log file if it was opened.
Definition: Logger.cpp:99
static Logger * GetInstance()
Get the Logger object.
Definition: Logger.cpp:41
Logger(const Logger &)=delete