Poco C++ 简单的日志封装
2014-04-04 14:57
232 查看
#pragma once #ifndef ___UTIL_POCOLOGUTIL_H___ #define ___UTIL_POCOLOGUTIL_H___ #include "Poco/ConsoleChannel.h" #include "Poco/FormattingChannel.h" #include "Poco/PatternFormatter.h" #include "Poco/Logger.h" #include "Poco/AutoPtr.h" #include "Poco/FileChannel.h" #include "Poco/LocalDateTime.h" #include "Poco/Thread.h" using Poco::ConsoleChannel; using Poco::FormattingChannel; using Poco::PatternFormatter; using Poco::Logger; using Poco::AutoPtr; using Poco::FileChannel; using Poco::Thread; using Poco::LocalDateTime; namespace PocoUtil { namespace LogHelper { #pragma region Declaration class EasyLog { public: static EasyLog * Inst(){ if (0 == _instance.get()){ _instance.reset(new EasyLog); } return _instance.get(); } /* 写日志的方法(可配置ISACTIVE,设置是否回显到控制台) @msg 日志信息 */ void Log(std::string msg); private: EasyLog(void); virtual ~EasyLog(void){} friend class std::auto_ptr<EasyLog>; static std::auto_ptr<EasyLog> _instance; void LogInit(); }; #pragma endregion #pragma region Definition std::auto_ptr<EasyLog> EasyLog::_instance; EasyLog::EasyLog() { LogInit(); } void EasyLog::LogInit() { AutoPtr<FileChannel> pChannel(new FileChannel); pChannel->setProperty("path", "Poco.log"); pChannel->setProperty("rotation", "never"); pChannel->setProperty("archive", "timestamp"); AutoPtr<PatternFormatter> pPF(new PatternFormatter); pPF->setProperty("pattern", "%Y-%m-%d %H:%M:%S %s: %t"); pPF->setProperty("times","local"); AutoPtr<FormattingChannel> pFC(new FormattingChannel(pPF, pChannel)); Logger::root().setChannel(pFC); } void EasyLog::Log(std::string loginfo) { Logger::get(" ---> ").information(loginfo); } #pragma endregion } } #endif // end of ___UTIL_EASYLOG_H___
相关文章推荐
- C语言实现简单的日志封装
- Java日志 - log4简单使用实例及其再次封装
- Android日志简单封装
- 简单、易用的光盘封装工具-MKISO纪念版(V1.0.2.0)发布日志
- Log日志框架-对原生Log进行简单封装
- Android log 日志打印简单封装
- 一个简单日志封装
- 一个简单的封装 .net的日志功能
- RUBY的类封装,继承,多态简单演示
- 对commons fileupload组件的简单封装
- LogStash,使日志管理更简单
- Android--Retrofit+RxJava的简单封装(三)
- 集折叠、选项卡、焦点图的封装,简单实用
- 比较简单的Web请求(get/post)方法封装,调用网络接口时能用到
- winfrom下使用log4简单配置日志
- 简单封装的httpclient
- iOS sqlite 增删改查 简单封装(基于 FMDB)
- Qt中简单的日志文件实现
- DomDocument使用及简单封装
- JS封装简单后代选择器