! 4 space instead of tab & remove global std
[scx.git] / include / Log.hpp
blobc755b4ae8bb202337a144fedf37bbd70bb1d48af
1 #ifndef SCX_LOG_HPP
2 #define SCX_LOG_HPP
4 #include <iostream>
5 #include <fstream>
6 #include <sstream>
7 #include <string>
8 #include "Mutex.hpp"
9 #include "ColStr.hpp"
11 namespace scx
13 class Log
15 public:
16 Log()
18 EnableStdOut(true);
19 EnableFileOut(false);
22 ~Log()
24 Close();
27 bool Open(const std::string& file = "log.txt")
29 m_FileStream.open(file.c_str(), std::ios::out);
30 if (m_FileStream.is_open())
31 return true;
32 else
33 return false;
36 void Close()
38 if (m_FileStream.is_open())
39 m_FileStream.close();
42 stringstream& Info()
44 return m_StrStream;
47 stringstream& Warning()
49 return m_StrStream;
52 stringstream& Error()
54 return m_StrStream;
57 template <typename T>
58 ostream& operator<<(T& val)
60 m_FileStream << val;
61 cout << val;
62 return m_FileStream;
65 ostream& operator<<(ostream& (*fn)(ostream&))
67 m_FileStream << fn;
68 cout << fn;
69 return m_FileStream;
72 ostream& operator<<(ios& (*fn)(ios&))
74 return m_FileStream;
77 private:
78 Mutex m_Mutex;
79 bool m_EnableStdOut;
80 bool m_EnableFileOut;
81 std::ofstream m_FileStream;
82 std::stringstream m_StrStream;
85 class ColorStream
87 public:
88 template <typename T>
89 ostream& operator<<(T&)
94 private:
99 #endif