spacewander commented on code in PR #7749:
URL: https://github.com/apache/apisix/pull/7749#discussion_r950843464
##########
apisix/plugins/log-rotate.lua:
##########
@@ -251,7 +263,18 @@ local function rotate()
if now_time < rotate_time then
-- did not reach the rotate time
core.log.info("rotate time: ", rotate_time, " now time: ", now_time)
- return
+
+ local log_file =
assert(io_open(default_logs[DEFAULT_ACCESS_LOG_FILENAME].file, "r"))
+ local access_log_file_size = file_size(log_file)
+ log_file:close()
+
+ log_file =
assert(io_open(default_logs[DEFAULT_ERROR_LOG_FILENAME].file, "r"))
+ local error_log_file_size = file_size(log_file)
+ log_file:close()
+
+ if max_size <= 0 or access_log_file_size < max_size and
error_log_file_size < max_size then
Review Comment:
It seems the error log file will be rotated when the access log is too big?
##########
apisix/plugins/log-rotate.lua:
##########
@@ -251,7 +263,18 @@ local function rotate()
if now_time < rotate_time then
-- did not reach the rotate time
core.log.info("rotate time: ", rotate_time, " now time: ", now_time)
- return
+
+ local log_file =
assert(io_open(default_logs[DEFAULT_ACCESS_LOG_FILENAME].file, "r"))
Review Comment:
We can use `lfs.attributes` to get it.
##########
apisix/plugins/log-rotate.lua:
##########
@@ -251,7 +263,18 @@ local function rotate()
if now_time < rotate_time then
-- did not reach the rotate time
core.log.info("rotate time: ", rotate_time, " now time: ", now_time)
- return
+
+ local log_file =
assert(io_open(default_logs[DEFAULT_ACCESS_LOG_FILENAME].file, "r"))
+ local access_log_file_size = file_size(log_file)
+ log_file:close()
+
+ log_file =
assert(io_open(default_logs[DEFAULT_ERROR_LOG_FILENAME].file, "r"))
+ local error_log_file_size = file_size(log_file)
+ log_file:close()
+
+ if max_size <= 0 or access_log_file_size < max_size and
error_log_file_size < max_size then
Review Comment:
```suggestion
if max_size <= 0 or (access_log_file_size < max_size and
error_log_file_size < max_size) then
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]