测试最新的log4cplus1.1.2版
#include "stdafx.h"
#include <sstream>
class AB{
public:
void do_test()
{
//LOG_DEBUG("abc");
//LOG4CPLUS_DEBUG(_Logger(), __if_exists(this){'[' << this << ']' <<} L'[' << __FUNCTION__ << "] " << "abc" );
do
{
if((_Logger()).isEnabledFor(log4cplus::DEBUG_LOG_LEVEL))
{
log4cplus::tostringstream _log4cplus_buf;//tostringstream
_log4cplus_buf << __if_exists(this){'[' << this << ']' <<} L'[' << __FUNCTION__ << "] " << "abc";
(_Logger()).forcedLog(log4cplus::DEBUG_LOG_LEVEL, _log4cplus_buf.str(), "e:\\work\\testlog4cplus\\main.cpp", 10);
}
} while (0);
}
// LOG_CLS_DEC();
// LOG_CLS_DEC_EX( log4cplus_tool::GetModuleLoggerName() + LOG4CPLUS_TEXT('.') + LOG4CPLUS_C_STR_TO_TSTRING(__FUNCTION__) )
static log4cplus::Logger & _Logger()
{
log4cplus::tstring s = log4cplus_tool::GetModuleLoggerName() + L'.' + log4cplus::helpers::towstring( __FUNCTION__ );
size_t nPos = s.find(TCHAR(':'));
s = s.substr(0, nPos);
static log4cplus::Logger& s_logger = log4cplus::Logger::getInstance( s );
return s_logger;
};
};
void InitLog4cplusCfg()
{
TCHAR szPath[MAX_PATH] = _T("");
GetModuleFileName(NULL, szPath, MAX_PATH);
ATLPath::Combine(szPath, szPath, _T("..\\log4cplus_test.cfg"));
//LOG_INIT_EX(szPath);
log4cplus::PropertyConfigurator::doConfigure(szPath);
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
InitLog4cplusCfg();
AB ab;
ab.do_test();
return 1;
}