comparison common/logstream.h @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 #ifndef _LOGSTREAM_H_
2 #define _LOGSTREAM_H_
3
4 #ifdef QT_VERSION
5 #include <QString>
6 #endif
7
8 #include "logtypes.h"
9
10 #include <common.h>
11
12 #include <sstream>
13 #include <string>
14 #include <iomanip>
15 #include <type_traits>
16
17 class logstream
18 {
19 public:
20
21 logstream() = delete;
22 logstream(int line, const char pFile[], const char pFunc[], unafrog::log::LogLevel level);
23
24 virtual ~logstream();
25
26 template<class T>
27 logstream &operator<<(T t)
28 {
29 const bool is_bool = std::is_same<T,bool>::value;
30 std::string out = is_bool?(t ? "true" : "false") : unafrog::utils::to_string(t);
31 mOutputStream << out;
32 return appendSpace();
33 }
34
35 logstream &operator<<(void* t)
36 {
37 mOutputStream << "0x" << std::uppercase << std::setfill('0') << std::setw(8) << std::hex << t;
38 return appendSpace();
39 }
40
41 logstream &operator<<(const char* t)
42 {
43 mOutputStream << t;
44 return appendSpace();
45 }
46
47 logstream &operator<<(const std::string& t)
48 {
49 return operator<<(t.c_str());
50 }
51
52 #ifdef QT_VERSION
53 logstream &operator<<(const QString& t)
54 {
55 return operator<<(t.toUtf8().constData());
56 }
57 #endif
58
59 private:
60 logstream &operator=(const logstream &rOther);
61 logstream(const logstream &rOther);
62
63 logstream &appendSpace();
64
65 private:
66 std::stringstream mOutputStream;
67 std::string mFile;
68 std::string mFunc;
69 unafrog::log::LogLevel mLevel;
70 int mLine;
71 };
72
73 #endif // logstream_H