tzssangglass commented on a change in pull request #5715: URL: https://github.com/apache/apisix/pull/5715#discussion_r763646799
########## File path: apisix/plugins/log-rotate.lua ########## @@ -194,18 +231,33 @@ local function rotate() core.log.info("rotate interval:", interval) core.log.info("rotate max keep:", max_kept) - local time = ngx.time() - if time % interval == 0 then - time = time - interval - else - time = time - time % interval + if not default_logs then + -- first init default log filepath and filename + default_logs = {} + init_default_logs(default_logs, DEFAULT_ACCESS_LOG_FILENAME) + init_default_logs(default_logs, DEFAULT_ERROR_LOG_FILENAME) end - local date_str = os.date("%Y-%m-%d_%H-%M-%S", time) + local now_time = ngx_time() Review comment: do we need to update time by `ngx.update_time` here? ########## File path: apisix/plugins/log-rotate.lua ########## @@ -194,18 +231,33 @@ local function rotate() core.log.info("rotate interval:", interval) core.log.info("rotate max keep:", max_kept) - local time = ngx.time() - if time % interval == 0 then - time = time - interval - else - time = time - time % interval + if not default_logs then + -- first init default log filepath and filename + default_logs = {} + init_default_logs(default_logs, DEFAULT_ACCESS_LOG_FILENAME) + init_default_logs(default_logs, DEFAULT_ERROR_LOG_FILENAME) end - local date_str = os.date("%Y-%m-%d_%H-%M-%S", time) + local now_time = ngx_time() + if not rotate_time then + -- first init rotate time + rotate_time = now_time + interval + core.log.info("first init rotate time is: ", rotate_time) + return + end + + if now_time < rotate_time then + -- did not reach the rotate time + core.log.info("rotate time: ", rotate_time, " now time: ", now_time) + return + end - local ok1 = rotate_file(date_str, "access.log") - local ok2 = rotate_file(date_str, "error.log") - if not ok1 and not ok2 then + local now_date = os_date("%Y-%m-%dT%H-%M-%S", now_time) Review comment: the origin format is `"%Y-%m-%d_%H-%M-%S"`, I think wo should follow this. Some log capture systems just use regular matching filenames to capture log files. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org