| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #pragma once
- #ifndef _DNC_LOG
- #define _DNC_LOG
- #include<log4cpp/Category.hh>
- #include<log4cpp/OstreamAppender.hh>
- #include<log4cpp/Priority.hh>
- #include<log4cpp/PatternLayout.hh>
- #include<log4cpp/FileAppender.hh>
- #include "log4cpp/PropertyConfigurator.hh"
- #include <string>
- #include <sstream>
- #include <boost/algorithm/string.hpp>
- #include <boost/format.hpp>
- using Format = boost::format;
- #define NONE "\e[0m"
- #define L_RED "\e[1;31m"
- #define YELLOW "\e[1;33m"
- #define L_BLUE "\e[1;34m"
- #define L_CYAN "\e[1;36m"
- #define LOG_DEBUG MYLog::instance()->getLogType()->debug
- #define LOG_INFO MYLog::instance()->getLogType()->info
- #define LOG_WARN MYLog::instance()->getLogType()->warn
- #define LOG_ERROR MYLog::instance()->getLogType()->error
- #define LOG_DEBUG_S(msg) \
- printf(L_BLUE); \
- LOG4CPP_DEBUG_S((*(MYLog::instance()->getLogType())))<<msg<< "\n" <<"("<<__FILE__<< ":" << __FUNCTION__ << ":" << __LINE__ << ")"; \
- printf(NONE);
- #define LOG_INFO_S(msg) \
- printf(L_CYAN); \
- LOG4CPP_INFO_S((*(MYLog::instance()->getLogType())))<<msg<< "\n" <<"("<<__FILE__<< ":" << __FUNCTION__ << ":" << __LINE__ << ")"; \
- printf(NONE);
- #define LOG_WARN_S(msg) \
- printf(YELLOW); \
- LOG4CPP_WARN_S((*(MYLog::instance()->getLogType())))<<msg<< "\n" <<"("<<__FILE__<< ":" << __FUNCTION__ << ":" << __LINE__ << ")"; \
- printf(NONE);
- #define LOG_ERROR_S(msg) \
- printf(L_RED); \
- LOG4CPP_ERROR_S((*(MYLog::instance()->getLogType()))) << msg << "\n" <<"("<<__FILE__<< ":" << __FUNCTION__ << ":" << __LINE__ << ")"; \
- printf(NONE);
-
- class MYLog {
- public:
-
- int Init(std::string initfilename) {
- try {
- log4cpp::PropertyConfigurator::configure(initfilename);
- }
- catch (log4cpp::ConfigureFailure&f) {
- std::cout << "Configure Problem " << f.what() << std::endl;//失败
- return -1;
- }
- return 0;
- }
- static MYLog* instance() {
- return &_instance;
- }
- log4cpp::Category* getLogType()
- {
- return _category;
- }
-
- protected:
- MYLog() {};
- static MYLog _instance;
- static log4cpp::Category* _category;
- };
- #endif
|