Closed kizy008 closed 2 years ago
i meet same problem。can u show u code?
Do you follow the two steps ?
- rename old log file and create new one
- notify other processes to reopen the file
Do you follow the two steps ?
how to notify other processes
You could use ngx.shared.dict to notify other processes. For example
-- process 1
local rotate = ngx.shared.rotate
rotate:set("reopen", true)
-- process 2
local rotate = ngx.shared.rotate
local reopen = rotate:get("reopen")
if reopen then
-- reopen file
end
Since this is your own code, not related to the project, I turned it into discussion.
Description
In my project, I need split log file by hour and delete logs 7 days ago. So I write a rotate plugin like [log-rotate.lua], and it works. But I found that every new log file contains the history log message. For example, [log-2022-09-01_01-00-00.log] contains all message in [log-2022-09-01_00-00-00.log]]. So every log contains all history message. I think the new log should contains message in its hour period. But I got all history message. I want to know how to get incremental logs in new log file.
我的项目中需要将日志按照小时分割并自动淘汰7天前的历史日志。 所以我仿照[log-rotate.lua]写了file-logger的滚动切割日志插件,并且按照预期生效了。但是我发现,所有的心日志文件都包含了全量的历史日志。比如 [log-2022-09-01_01-00-00.log]日志不仅包含了23点到0点的日志, 还包含了所有的历史全量日志。我本以为新日志应该只包含过去1个小时之内的日志。 我想知道如何利用file-logger在每个日志文件中保存这个小时时间段内增量的日志呢?
Environment
apisix version
):uname -a
):openresty -V
ornginx -V
):curl http://127.0.0.1:9090/v1/server_info
):luarocks --version
):