#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,
	PARSE_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",
	"parse_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;
};