|
可以通过变量控制日志记录,循环记录,不会无限占用磁盘空间。
使用方法,在机器人循环中加入daily_log()调用即可,建议放到固定循环中,如:checkPrepare() idle_set()
- var.id = 'joyce'
- var.logtofile = 1 -- 1-记,nil=不计,日志在logs目录下
- var.log_count = 10 -- 日志循环数量
- var.log_file_max_size = 1024*1024*100 -- 日志大小
复制代码
- function daily_log()
- local dir = GetInfo (67) .. "logs\"
- local seq = '1'
- local filename = var.log_file or var.id..' '..seq..'.log'
- if IsLogOpen() then
- FlushLog()
- if GetInfo(231) > var.log_file_max_size*1 then
- local oldname = GetInfo(51)
- local now_seq,next_seq
- local set = utils.split(oldname,'\\')
- oldname = set[#set]
- print(oldname)
- now_seq = string.gsub(oldname,var.id..' ','')
- now_seq = string.gsub(now_seq,'.log','')
- print(now_seq)
- if 1*now_seq >= 1*var.log_count then
- next_seq = 1
- else
- next_seq = now_seq + 1
- end
- CloseLog()
- filename = var.id..' '..next_seq..'.log'
- var.log_file = filename
- return OpenLog(dir..filename, false)
- end
- else
- return OpenLog(dir..filename, true)
- end
- end
复制代码 |
评分
-
1
查看全部评分
-
|