log4z icon indicating copy to clipboard operation
log4z copied to clipboard

日志自动清除

Open txwhhny opened this issue 5 years ago • 2 comments

你好,可以自动清除日志吗,或者能循环记录,避免日志文件占用空间无限增长,setLoggerReserveTime似乎,只对本次运行的进程有效,程序重新启动,并不检查过往的日志文件是否已经超过保留时间。请问还有其他解决方法吗

txwhhny avatar Dec 20 '19 09:12 txwhhny

   //-daystart从当天开始的时刻算起,  -mtime 文件的创建时间
string cmdStr = "find ./logs/* -daystart -mtime +7 -delete";//7天
myprintf("cmd:[%s]\n", cmdStr.c_str());
system(cmdStr.c_str());

每天执行一次,删除超过7天的。你看这个怎么样。

alongL avatar Aug 31 '20 02:08 alongL

   //-daystart从当天开始的时刻算起,  -mtime 文件的创建时间
string cmdStr = "find ./logs/* -daystart -mtime +7 -delete";//7天
myprintf("cmd:[%s]\n", cmdStr.c_str());
system(cmdStr.c_str());

每天执行一次,删除超过7天的。你看这个怎么样。

感谢你的回答,自己处理是可以实现,如果库里面有支持,就直接用了

txwhhny avatar Sep 04 '20 09:09 txwhhny