-
-
Notifications
You must be signed in to change notification settings - Fork 942
/
Copy pathmake-loggable.cpp
41 lines (33 loc) · 1002 Bytes
/
make-loggable.cpp
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
//
// This file is part of Easylogging++ samples
//
// Usage of MAKE_LOGGABLE to make class log-friendly
//
// Revision 1.1
// @author abumq (Majid Q.)
//
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
class Integer {
public:
Integer(int i) : m_underlyingInt(i) {}
Integer& operator=(const Integer& integer) { m_underlyingInt = integer.m_underlyingInt; return *this; }
virtual ~Integer(void) { m_underlyingInt = -1; }
int getInt(void) const { return m_underlyingInt; }
inline operator int() const { return m_underlyingInt; }
private:
int m_underlyingInt;
};
// Lets say Integer class is in some third party library
// We use MAKE_LOGGABLE(class, instance, outputStream) to make it loggable
inline MAKE_LOGGABLE(Integer, integer, os) {
os << integer.getInt();
return os;
}
int main(void) {
Integer count = 5;
LOG(INFO) << "Integer count = " << count;
int reverse = count;
LOG(INFO) << "int reverse = " << reverse;
return 0;
}