#include <log4cplus/logger.h>
#include <log4cplus/consoleappender.h>
#include <log4cplus/fileappender.h>
#include <log4cplus/layout.h>
#include <log4cplus/configurator.h>
#include "log.h"
using namespace log4cplus;
using namespace log4cplus::helpers;
Logger logger = Logger::getRoot();;
CLog::CLog()
{
}
CLog::~CLog()
{
LOG4CPLUS_INFO( logger, " ====================日志记录停止 ====================" );
}
#define DO_LOGGER(logLevel, filename, fileline, pFormat)\
if(logger.isEnabledFor(logLevel))\
{ \
va_list args; \
va_start(args, pFormat); \
char buf[1024] = {0}; \
_vsnprintf_s(buf, sizeof(buf), pFormat, args); \
va_end(args); \
log4cplus::tostringstream _log4cplus_buf; \
_log4cplus_buf << buf; \
logger.forcedLog(logLevel, _log4cplus_buf.str(), filename, fileline); \
}
void CLog::Debug( const char* filename, const int fileline, const char* pFormat, ... )
{
DO_LOGGER(log4cplus::DEBUG_LOG_LEVEL, filename, fileline, pFormat);
}
void CLog::Error( const char* filename, const int fileline, const char* pFormat, ... )
{
DO_LOGGER( log4cplus::ERROR_LOG_LEVEL, filename, fileline, pFormat);
}
void CLog::Fatal( const char* filename, const int fileline, const char* pFormat, ... )
{
DO_LOGGER( log4cplus::FATAL_LOG_LEVEL, filename, fileline, pFormat);
}
void CLog::Info( const char* filename, const int fileline, const char* pFormat, ... )
{
DO_LOGGER( log4cplus::INFO_LOG_LEVEL, filename, fileline, pFormat);
}
void CLog::Warn( const char* filename, const int fileline, const char* pFormat, ... )
{
DO_LOGGER( log4cplus::WARN_LOG_LEVEL, filename, fileline, pFormat);
}
void CLog::Trace( const char* filename, const int fileline, const char* pFormat, ... )
{
DO_LOGGER( log4cplus::TRACE_LOG_LEVEL, filename, fileline, pFormat);
}
void CLog::InitLogger()
{
std::locale::global(std::locale("chs"));
PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties"));
LOG4CPLUS_INFO( logger, " ====================日志记录启动 ====================" );
}