You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "leslie-tsang (via GitHub)" <gi...@apache.org> on 2023/03/31 05:31:07 UTC

[GitHub] [apisix] leslie-tsang commented on a diff in pull request #9210: feat: Add support for custom named log file names for log-rotate plugin

leslie-tsang commented on code in PR #9210:
URL: https://github.com/apache/apisix/pull/9210#discussion_r1154028653


##########
t/plugin/log-rotate3.t:
##########
@@ -132,3 +132,41 @@ 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:
+    user: root
+    error_log: /home/cc/log/service/docker_nginx_apisix_error.log
+    http:
+        access_log: /home/cc/log/service/apisix_apigateway_apisix_access.log
+--- config
+    location /t {
+        content_by_lua_block {
+            ngx.sleep(3.5)
+            local has_split_access_file = false
+            local has_split_error_file = false
+            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
+--- timeout: 5

Review Comment:
   Need a new line at the end of the test case.



##########
apisix/plugins/log-rotate.lua:
##########
@@ -265,6 +265,22 @@ local function rotate_file(files, now_time, max_kept)
     end
 end
 
+local function get_custom_logfile_name()
+    local custom_file_name = core.config.local_conf()
+
+    local new_error_log = core.table.try_read_attr(local_conf, "nginx_config", "error_log")
+    local new_access_log = core.table.try_read_attr(local_conf, "nginx_config", "http", "access_log")
+
+    if new_access_log then
+        DEFAULT_ACCESS_LOG_FILENAME = new_access_log

Review Comment:
   Should we do it during the loading phase because it will not change until it is reloaded or restarted.
   > BTW, it's not a good idea to change the constants.



-- 
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-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org