|
@@ -86,7 +86,7 @@ int MyLog::test()
|
|
|
|
|
|
bRet = IsDirExist(dir);
|
|
|
if (!bRet) {
|
|
|
- CreateDir(dir);
|
|
|
+ CreateDir(dir.c_str());
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
@@ -95,9 +95,15 @@ int MyLog::test()
|
|
|
int MyLog::InitLogConfig()
|
|
|
{
|
|
|
std::string name = my_log_file_name[fileType];
|
|
|
- std::string filename = strExeDir + "log/" + GetFileName();
|
|
|
+
|
|
|
std::string str_category = my_log_file_name[fileType] + "_category";
|
|
|
m_Lasttime = getCurTime();
|
|
|
+ std::string filepath = strExeDir + "log\\" + m_Lasttime + "\\";
|
|
|
+ if (!IsDirExist(filepath))
|
|
|
+ {
|
|
|
+ CreateDir(filepath.c_str());
|
|
|
+ }
|
|
|
+ std::string filename = filepath + GetFileName();
|
|
|
pLayout = new log4cpp::PatternLayout();
|
|
|
/*
|
|
|
%c category;
|
|
@@ -156,11 +162,47 @@ bool MyLog::IsDirExist(std::string path)
|
|
|
return bRet;
|
|
|
}
|
|
|
|
|
|
-bool MyLog::CreateDir(std::string path)
|
|
|
+bool MyLog::CreateDir(const char * pDir)
|
|
|
{
|
|
|
- std::string cmd = "md " + path;
|
|
|
- system(cmd.c_str());//创建一个文件夹
|
|
|
-
|
|
|
+ //std::string cmd = "md " + path;
|
|
|
+ //system(cmd.c_str());//创建一个文件夹
|
|
|
+ int i = 0;
|
|
|
+ int iRet;
|
|
|
+ int iLen;
|
|
|
+ char* pszDir;
|
|
|
+
|
|
|
+ if(NULL == pDir)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ pszDir = strdup(pDir);
|
|
|
+ iLen = strlen(pszDir);
|
|
|
+
|
|
|
+ // 创建中间目录
|
|
|
+ for (i = 0;i < iLen;i ++)
|
|
|
+ {
|
|
|
+ if (pszDir[i] == '\\' || pszDir[i] == '/')
|
|
|
+ {
|
|
|
+ pszDir[i] = '\0';
|
|
|
+
|
|
|
+ //如果不存在,创建
|
|
|
+ iRet = ACCESS(pszDir,0);
|
|
|
+ if (iRet != 0)
|
|
|
+ {
|
|
|
+ iRet = MKDIR(pszDir);
|
|
|
+ if (iRet != 0)
|
|
|
+ {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //支持linux,将所有\换成/
|
|
|
+ pszDir[i] = '/';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ iRet = MKDIR(pszDir);
|
|
|
+ free(pszDir);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -188,7 +230,13 @@ std::string MyLog::int2string(int value)
|
|
|
int MyLog::SetAppender(const char* filename)
|
|
|
{
|
|
|
std::string name = my_log_file_name[fileType];
|
|
|
- std::string strFileName = strExeDir + "log/" + filename;
|
|
|
+ //std::string strFileName = strExeDir + "log/" + filename;
|
|
|
+ std::string filepath = strExeDir + "log/" + m_Lasttime + "/";
|
|
|
+ if (!IsDirExist(filepath))
|
|
|
+ {
|
|
|
+ CreateDir(filepath.c_str());
|
|
|
+ }
|
|
|
+ std::string strFileName = filepath + filename;
|
|
|
|
|
|
pCategory->removeAppender(pAppender);
|
|
|
|