You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/08/22 02:14:55 UTC

[GitHub] [apisix] nic-chen commented on a change in pull request #2097: feature: implemented plugin `log-rotate`, rotate log by interval time.

nic-chen commented on a change in pull request #2097:
URL: https://github.com/apache/apisix/pull/2097#discussion_r475033975



##########
File path: apisix/plugins/log-rotate.lua
##########
@@ -0,0 +1,183 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local core = require("apisix.core")
+local process = require("ngx.process")
+local signal = require("resty.signal")
+local ngx = ngx
+local prefix = ngx.config.prefix()
+local lfs = require("lfs")
+local io = io
+local os = os
+local table = table
+local select = select
+local type = type
+
+
+local timer
+local plugin_name = "log-rotate"
+local INTERVAL = 60 * 60    -- one hour
+local MAX_KEPT = 24 * 7     -- 7 days
+local schema = {
+    type = "object",
+    properties = {},
+    additionalProperties = false,
+}
+
+
+local _M = {
+    version = 0.1,
+    priority = 100,
+    name = plugin_name,
+    schema = schema,
+}
+
+
+local function file_exists(path)
+    local file = io.open(path, "r")
+    if file then
+        file:close()
+    end
+    return file ~= nil
+end
+
+
+local function rotate_file(date_str, file_type)
+    local file_path = prefix .. "logs/" .. date_str .. "_" .. file_type

Review comment:
       > Note that user can customize their log paths.
   
   good catch. we need to check log path config in `config.yaml` first.




----------------------------------------------------------------
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.

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