]> git.stg.codes - ssmd.git/blob - include/logger.h
7207003a92c998fd07808d37f73f645905ec82f5
[ssmd.git] / include / logger.h
1 #ifndef __SSMD_LOGGER_H__
2 #define __SSMD_LOGGER_H__
3
4 #include <iostream>
5 #include <fstream>
6 #include <string>
7
8 #define LOG_IT logger << __FILE__ << "(" << __LINE__ << ") : "
9
10 namespace SSMD {
11
12 class Logger {
13 public:
14     Logger()
15         : fout(),
16           consoleLog(true)
17     {}
18     Logger(const std::string & fileName)
19         : fout(fileName.c_str(), std::ios::app),
20           logFile(fileName),
21           consoleLog(!fout.is_open())
22     {}
23     ~Logger() 
24     {};
25
26     bool setLogFile(const std::string & fileName);
27
28     std::ostream & operator<<(const std::string & str);
29 private:
30     std::ofstream fout;
31     std::string logFile;
32     bool consoleLog;
33
34     void _logDate();
35 };
36
37 }
38
39 extern SSMD::Logger logger;
40
41 #endif