1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include "StdAfx.h"
- #include "Log4cplusInitalizer.h"
- #include <log4cplus/logger.h>
- #include <log4cplus/configurator.h>
- #include <log4cplus/loggingmacros.h>
- #include <log4cplus/consoleappender.h>
- #include <log4cplus/layout.h>
- #include <log4cplus/fileappender.h>
- #include <log4cplus/helpers/loglog.h>
- #include <log4cplus/helpers/property.h>
- #include <memory>
- using namespace log4cplus;
- using namespace std;
- //Log4cplusInitalizer _log4cplusInitalizer;
- bool Log4cplusInitalizer::initalized = false;
- Log4cplusInitalizer::Log4cplusInitalizer(void)
- {
- }
- Log4cplusInitalizer::~Log4cplusInitalizer(void)
- {
- }
- void Log4cplusInitalizer::initalize()
- {
- if (initalized)return;
- initalized = true;
- std::locale::global(std::locale(""));
- log4cplus::initialize();
- helpers::LogLog::getLogLog()->setInternalDebugging(false);
- // 定义一个文件Appender
- SharedAppenderPtr pFileAppender(new FileAppender(LOG4CPLUS_TEXT("SmartEvaluationLogic.log"), std::ios_base::app));
- // 定义Logger
- Logger pTestLogger = Logger::getInstance(LOG4CPLUS_TEXT("LoggerName"));
- tstring pattern = LOG4CPLUS_TEXT("%D{%m/%d/%y %H:%M:%S} - %m [%l]%n");
- std::auto_ptr<Layout> _layout(new PatternLayout(pattern));
- pFileAppender->setLayout(_layout);
- // 将需要关联Logger的Appender添加到Logger上
- pTestLogger.addAppender(pFileAppender);
- // 输出日志信息
- LOG4CPLUS_INFO_STR(pTestLogger, LOG4CPLUS_TEXT("---->开始写日志------------>>>>>>>>"));
- LOG4CPLUS_INFO_FMT(pTestLogger, LOG4CPLUS_TEXT("---->开始写日志------------>>>>>>>>"));
- }
|