-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogable.h
More file actions
61 lines (48 loc) · 1.31 KB
/
Copy pathlogable.h
File metadata and controls
61 lines (48 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef CLOGABLE_H
#define CLOGABLE_H
#include "log4cxx/logger.h"
#include <QString>
#include <QBuffer>
#include <QDebug>
#include <string>
#include <utility>
#include <QTextStream>
#include <QDataStream>
//helper LoggerMacros
#define LOGGER_HELPER(LVL, msg ,ARGS...) \
msg = createMsg(ARGS); \
LOG4CXX_##LVL(m_logger, msg)
class CLogable
{
public:
CLogable(QString logName);
//protected member tahat defines a log
protected:
template <typename ...TArgs>
std::string createMsg(TArgs&&... args)
{
QString streamStr;
//QTextStream stream(&streamStr);
QDebug dbgStream(&streamStr);
createMsgImpl(dbgStream, std::forward<TArgs>(args)...);
return streamStr.toStdString();
}
log4cxx::LoggerPtr m_logger;
//prvate
template <typename TFirst, typename ...TArgs>
void createMsgImpl(QDebug& dbg, TFirst&& first, TArgs&&... args)
{
dbg << first << " ";
createMsgImpl(dbg, std::forward<TArgs>(args)...);
}
template<typename ...TArgs>
void createMsgImpl(QDebug& dbg, std::string str, TArgs&&... args)
{
dbg << str.c_str() << " ";
createMsgImpl(dbg, std::forward<TArgs>(args)...);
}
//stop recursion
void createMsgImpl(QDebug& /*dbg*/)
{}
};
#endif // CLOGABLE_H