LOG4CPP下载与编译
Log4cpp是一个开源的C++类库,它提供了在C++程序中使用日志和跟踪调试的功能。使用log4cpp,可以很便利地将日志或者跟踪调试信息写入字符流、内存字符串队列、文件、回滚文件、调试器、Windows日志、本地syslog和远程syslog服务器中。
下载地址为:http://sourceforge.net/projects/log4cpp/files/latest/download。(log4cpp-1.1.2rc1.tar.gz,仅 577K )
解压后,进入对应的msvc 文件夹(本人使用vs2013,进入了vsvc10,双击msvc10.sln 打开vs,项目列表如下:
)
直接编译(log4cpp项目,(log4cppLIB编译失败,失败原因:LINK : fatal error LNK1181: 无法打开输入文件“.\Debug\NTEventLogCategories.res”)),暂不处理,再次编译testDll,编译成功后,启动testDLL,显示文件找出不到。(log4cpp\msvc10\log4cpp\Debug\log4cpp.dll 到 log4cpp\msvc10\testDLL\Debug 即可。)
LOG4CPP 在项目中使用
#include <string>
#include "log4cpp/Priority.hh"
#include "log4cpp/Category.hh"
class Log4CppLog
{
public:
Log4CppLog();
Log4CppLog(std::wstring logPath, std::wstring logLevel);
~Log4CppLog();
void SetLogPath(std::wstring logPath, std::wstring logLevel);
bool IsDebugEnable();
void WriteLog(std::wstring logLevel, const std::string& msg);
void WriteLog(std::wstring logLevel, const std::string& fmt, const std::string& arg0);
void WriteLog(std::wstring logLevel, const std::string& fmt, const std::string& arg0, const std::string& arg1);
void WriteLog(std::wstring logLevel, const std::string& fmt, const std::string& arg0, const std::string& arg1, const std::string& arg2);
private:
log4cpp::Priority::PriorityLevel ChangeStringToPriorityLevel(std::wstring level);
void WriteLog4CppLog(log4cpp::Priority::PriorityLevel level, std::string logDate);
private:
std::string strProcessId;
std::wstring strLogPath;
log