Commit 36107efe by ZhongJianfu

update:日志超限备份

parent 49ac57da
#include "my_easylogging.h" #include "my_easylogging.h"
// #include <ctime> #include <ctime>
using namespace std; using namespace std;
INT32 G_LOG_ENABLE = 0; //调试中的变量,写0就好了。写1则开启相应打印 INT32 G_LOG_ENABLE = 0; //调试中的变量,写0就好了。写1则开启相应打印
...@@ -46,7 +46,10 @@ void rolloutHandler(const char *filename, std::size_t size) ...@@ -46,7 +46,10 @@ void rolloutHandler(const char *filename, std::size_t size)
{ {
/// 备份日志 /// 备份日志
static unsigned int idx; static unsigned int idx;
time_t nowtime;
struct tm *p;
time(&nowtime);
p = localtime(&nowtime);
#if defined(_WIN32) #if defined(_WIN32)
cout << "###########LOG SIZE FULL#############" << endl; cout << "###########LOG SIZE FULL#############" << endl;
std::stringstream ss; std::stringstream ss;
...@@ -56,11 +59,14 @@ void rolloutHandler(const char *filename, std::size_t size) ...@@ -56,11 +59,14 @@ void rolloutHandler(const char *filename, std::size_t size)
replace(cc.begin(), cc.end(), '/', '\\'); replace(cc.begin(), cc.end(), '/', '\\');
system(cc.c_str()); system(cc.c_str());
#else #else
/*下面这段没有测试过 需要优化*/ /*下面这段 需要优化*/
// system("mkdir bin"); // system("mkdir bin");
std::stringstream ss; std::stringstream ss;
std::time_t t = std::time(0); // t is an integer type
ss << "mv " ss << "mv "
<< filename << " ./log/log_backup_" << ++idx; << filename << " ./log/log_backup_" << ++idx << "_" << p->tm_year << p->tm_mon << p->tm_mday << ".log";
system(ss.str().c_str()); system(ss.str().c_str());
#endif #endif
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
TO_FILE = true TO_FILE = true
TO_STANDARD_OUTPUT = false TO_STANDARD_OUTPUT = false
PERFORMANCE_TRACKING = false PERFORMANCE_TRACKING = false
MAX_LOG_FILE_SIZE = 1 MAX_LOG_FILE_SIZE = 209715200
FILENAME = "./log/info_%datetime{%Y%M%d}.log" FILENAME = "./log/info_%datetime{%Y%M%d}.log"
* INFO: * INFO:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment