需要自己先包裹一下,用起来方便点。
头文件
#include <log4cxx/logger.h>
#include <log4cxx/stream.h>
#include <log4cxx/level.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/exception.h>
//使用这四个宏输出日志
#define LOG_DEBUG(msg) Log::GetInstance()->Debug()<<msg<<LOG4CXX_ENDMSG
#define LOG_INFO(msg) Log::GetInstance()->Info()<<msg<<LOG4CXX_ENDMSG
#define LOG_WARN(msg) Log::GetInstance()->Warn()<<msg<<LOG4CXX_ENDMSG
#define LOG_ERROR(msg) Log::GetInstance()->Error()<<msg<<LOG4CXX_ENDMSG
class Log{
private:
explicit Log(const std::string &strConfigFile);
~Log();
Log(const Log &) = delete;
Log &operator=(const Log &) = delete;
public:
static Log *GetInstance(