This is an automated email from the ASF dual-hosted git repository.

monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 5d649bfa6 fix(log-rotate): can not keep max files when using custom 
name (#9749)
5d649bfa6 is described below

commit 5d649bfa66d0ba1f85df635e6b73a3364733fa37
Author: Liu Wei <[email protected]>
AuthorDate: Fri Jun 30 16:01:16 2023 +0800

    fix(log-rotate): can not keep max files when using custom name (#9749)
---
 apisix/plugins/log-rotate.lua |  6 ++--
 t/plugin/log-rotate3.t        | 73 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/apisix/plugins/log-rotate.lua b/apisix/plugins/log-rotate.lua
index 61bcea163..14e4c45c7 100644
--- a/apisix/plugins/log-rotate.lua
+++ b/apisix/plugins/log-rotate.lua
@@ -113,14 +113,14 @@ end
 local function scan_log_folder(log_file_name)
     local t = {}
 
-    local log_dir, _ = get_log_path_info(log_file_name)
+    local log_dir, log_name = get_log_path_info(log_file_name)
 
-    local compression_log_type = log_file_name .. COMPRESSION_FILE_SUFFIX
+    local compression_log_type = log_name .. COMPRESSION_FILE_SUFFIX
     for file in lfs.dir(log_dir) do
         local n = string_rfind(file, "__")
         if n ~= nil then
             local log_type = file:sub(n + 2)
-            if log_type == log_file_name or log_type == compression_log_type 
then
+            if log_type == log_name or log_type == compression_log_type then
                 core.table.insert(t, file)
             end
         end
diff --git a/t/plugin/log-rotate3.t b/t/plugin/log-rotate3.t
index 8e7b92eee..3f1edd95a 100644
--- a/t/plugin/log-rotate3.t
+++ b/t/plugin/log-rotate3.t
@@ -132,3 +132,76 @@ start xxxxxx
     }
 --- response_body
 passed
+
+
+
+=== TEST 4: max_kept effective on differently named compression files
+--- extra_yaml_config
+plugins:
+  - log-rotate
+plugin_attr:
+  log-rotate:
+    interval: 1
+    max_kept: 1
+    enable_compression: true
+--- yaml_config
+nginx_config:
+    error_log: logs/err1.log
+    http:
+        access_log: logs/acc1.log
+--- config
+    location /t {
+        error_log logs/err1.log info;
+        access_log logs/acc1.log;
+
+        content_by_lua_block {
+            ngx.sleep(3)
+            local lfs = require("lfs")
+            local count = 0
+            for file_name in lfs.dir(ngx.config.prefix() .. "/logs/") do
+                if string.match(file_name, ".tar.gz$") then
+                    count = count + 1
+                end
+            end
+            --- only two compression file
+            ngx.say(count)
+        }
+    }
+--- response_body
+2
+
+
+
+=== TEST 5: check whether new log files were created
+--- extra_yaml_config
+plugins:
+  - log-rotate
+plugin_attr:
+  log-rotate:
+    interval: 1
+    max_kept: 0
+    enable_compression: false
+--- yaml_config
+nginx_config:
+    error_log: logs/err2.log
+    http:
+        access_log: logs/acc2.log
+--- config
+    location /t {
+        error_log logs/err2.log info;
+        access_log logs/acc2.log;
+
+        content_by_lua_block {
+            ngx.sleep(3)
+            local lfs = require("lfs")
+            local count = 0
+            for file_name in lfs.dir(ngx.config.prefix() .. "/logs/") do
+                if string.match(file_name, "err2.log$") or 
string.match(file_name, "acc2.log$") then
+                    count = count + 1
+                end
+            end
+            ngx.say(count)
+        }
+    }
+--- response_body
+2

Reply via email to