membphis commented on a change in pull request #689:
URL: https://github.com/apache/apisix-dashboard/pull/689#discussion_r517334311



##########
File path: api/conf/conf.json
##########
@@ -10,6 +10,17 @@
     "dag-lib-path": "",
     "etcd": {
       "endpoints": "127.0.0.1:2379"
+    },
+    "log": {
+      "error_log": {
+        "level": "warn",
+        "file_path": ""

Review comment:
       what means empty string? It makes me confused

##########
File path: api/log/zap.go
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+package log
+
+import (
+       "os"
+
+       "go.uber.org/zap"
+       "go.uber.org/zap/zapcore"
+
+       "github.com/apisix/manager-api/conf"
+)
+
+var logger *zap.SugaredLogger
+
+func init() {
+       writeSyncer := fileWriter()
+       encoder := getEncoder()
+       logLevel := getLogLevel()
+       core := zapcore.NewCore(encoder, writeSyncer, logLevel)
+
+       zapLogger := zap.New(core, zap.AddCaller())
+
+       logger = zapLogger.Sugar()
+}
+
+func getLogLevel() zapcore.LevelEnabler {
+       level := zapcore.WarnLevel
+       switch conf.ErrorLogLevel {
+       case "debug":
+               level = zapcore.DebugLevel
+       case "info":
+               level = zapcore.InfoLevel
+       case "error":

Review comment:
       `notice`, `warn`, `crit`
   
   can we add more log level?

##########
File path: api/conf/conf.json
##########
@@ -10,6 +10,17 @@
     "dag-lib-path": "",
     "etcd": {
       "endpoints": "127.0.0.1:2379"
+    },
+    "log": {
+      "error_log": {
+        "level": "warn",
+        "file_path": ""
+      },
+      "rotate": {

Review comment:
       can we implement this feature later? 
   so we can remove those configurations at first.

##########
File path: .github/workflows/cli_test.yml
##########
@@ -0,0 +1,31 @@
+name: Test CLI

Review comment:
       we can not use CLI here, we need a better name

##########
File path: api/test/shell/cli_test.sh
##########
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+#
+# 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.
+#
+
+# 'make init' operates scripts and related configuration files in the current 
directory
+# The 'apisix' command is a command in the /usr/local/apisix,
+# and the configuration file for the operation is in the /usr/local/apisix/conf
+
+set -ex
+
+clean_up() {
+    git checkout conf/conf.json
+}
+
+trap clean_up EXIT
+
+sed -i 's/"file_path": ""/"file_path": ".\/error.log"/' conf/conf.json
+sed -i 's/warn/info/' conf/conf.json
+
+go run main.go &
+
+sleep 3
+
+if [ ! -f "./error.log" ]; then
+    echo "failed: failed to write log"
+    exit 1
+fi
+
+if [ ! cat "./error.log" | grep INFO ]; then
+    echo "failed: failed to write log on right level"
+    exit 1
+fi
+

Review comment:
       only one blank line at the end of file.
   
   and we need more test cases, check the error log when using different log 
level.




----------------------------------------------------------------
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:
[email protected]


Reply via email to