123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #pragma once
- #include <Windows.h>
- #include <string>
- #include <memory>
- #include <time.h>
- #include <vector>
- #include <log4cpp\Category.hh>
- #include <log4cpp\Appender.hh>
- #include <log4cpp\FileAppender.hh>
- #include <log4cpp\OstreamAppender.hh>
- #include <log4cpp\Layout.hh>
- #include <log4cpp\SimpleLayout.hh>
- #include <log4cpp\BasicLayout.hh>
- #include <log4cpp\PatternLayout.hh>
- #include <log4cpp\Priority.hh>
- #include <log4cpp\RollingFileAppender.hh>
- #include <log4cpp\DailyRollingFileAppender.hh>
- #define MAX_FILE_SIZE 200*1024*1024
- #define MAX_BACKUP_COUNTS 10
- enum FILE_TYPE {
- RAW_S = 0,
- SYNC_S,
- DIST_S,
- DISTEX_S,
- DISTXX_S,
- JSON_S,
- JSON_R,
- SQL_S,
- SYS_S,
- KALMAN_S,
- ALGO_S,
- FILE_TYPE_TOTLA
- };
- const std::string my_log_file_name[] = {
- "raw_s",
- "sync_s"
- "dist_s",
- "distex_s",
- "distxx_s",
- "json_s",
- "json_r",
- "sql_s",
- "sys_s",
- "kalman_s",
- "algo_s"
- };
- const std::string log_file_pattern[] = {
- "%m%n", //消息,换行符
- "[%d] : %m%n"
- };
- class MyLog
- {
- public:
- MyLog(FILE_TYPE type);
- MyLog(FILE_TYPE type,bool status);
- ~MyLog();
- public:
- int WriteLog(const std::string msg);
- int WriteLog(const char* pMsg,...);
- int test();
- public:
- bool flag;
- private:
- bool status; //是否输出时间
- private:
- //以下函数考虑移出本类
- std::string GetExeDir(); //获得exe程序所在目录
- bool IsDirExist(std::string path); //检查目录是否存在
- bool CreateDir(std::string path); //创建目录
- std::string TCHAR2string(TCHAR* tch);
- std::string int2string(int value);
- public:
- int SetAppender(const char* filename);
- int SetAppender(std::string filename);
- int SetLayout(bool status);
- FILE_TYPE GetFileType(){return fileType;}
- bool GetStatus(){return status;}
- private:
- int InitLogConfig();
- long GetFileSize();
- std::string GetFileName();
- private:
- std::string strExeDir;
- private:
- FILE_TYPE fileType;
- std::string curFileName;
- int curFileCount;
- log4cpp::Appender* pAppender;
- log4cpp::PatternLayout* pLayout;
- log4cpp::Category* pCategory;
- };
|