encfs/vendor/github.com/muflihun/easyloggingpp/samples/STL/make-loggable.cpp
Valient Gough 5f0806c5cc Add "easylogging" from "https://github.com/muflihun/easyloggingpp@master"
git-vendor-name: easylogging
git-vendor-dir: vendor/github.com/muflihun/easyloggingpp
git-vendor-repository: https://github.com/muflihun/easyloggingpp
git-vendor-ref: master
2017-08-05 23:23:41 -07:00

42 lines
995 B
C++

//
// This file is part of Easylogging++ samples
//
// Usage of MAKE_LOGGABLE to make class log-friendly
//
// Revision 1.1
// @author mkhan3189
//
#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;
}