tokers commented on a change in pull request #4483:
URL: https://github.com/apache/apisix/pull/4483#discussion_r659123699



##########
File path: apisix/plugins/kafka-logger.lua
##########
@@ -152,8 +166,15 @@ function _M.log(conf, ctx)
         -- core.log.info("origin entry: ", entry)
 
     else
-        entry = log_util.get_full_log(ngx, conf)
-        core.log.info("full log entry: ", core.json.delay_encode(entry))
+        local metadata = plugin.plugin_metadata(plugin_name)
+        core.log.info("metadata: ", core.json.delay_encode(metadata))
+        if metadata and metadata.value.log_format 
+            and core.table.nkeys(metadata.value.log_format) > 0 then
+            entry = log_util.get_custom_format_log(metadata.value.log_format)
+        else
+            entry = log_util.get_full_log(ngx, conf)
+            core.log.info("full log entry: ", core.json.delay_encode(entry))

Review comment:
       Should also print this log for the "custom_format_log".

##########
File path: t/plugin/kafka-logger.t
##########
@@ -722,3 +722,43 @@ GET /t
 [qr/partition_id: 1/,
 qr/partition_id: 0/,
 qr/partition_id: 2/]
+
+
+
+=== TEST 20: add plugin metadata
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/plugin_metadata/kafka-logger',
+                ngx.HTTP_PUT,
+                [[{
+                    "log_format": {
+                        "host": "$host",
+                        "@timestamp": "$time_iso8601",
+                        "client_ip": "$remote_addr"
+                    }
+                }]],
+                [[{
+                    "node": {
+                        "value": {
+                            "log_format": {
+                                "host": "$host",
+                                "@timestamp": "$time_iso8601",
+                                "client_ip": "$remote_addr"
+                            }
+                        }
+                    },
+                    "action": "set"
+                }]]
+                )
+            ngx.status = code
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]

Review comment:
       Please check the editor, the EOL symbol is required.

##########
File path: docs/zh/latest/plugins/kafka-logger.md
##########
@@ -171,6 +171,33 @@ HTTP/1.1 200 OK
 hello, world
 ```
 
+## 插件元数据设置
+
+| 名称             | 类型    | 必选项 | 默认值        | 有效值  | 描述                        
                     |
+| ---------------- | ------- | ------ | ------------- | ------- | 
------------------------------------------------ |
+| log_format       | object  | 可选   |               |         | 以 Hash 
对象方式声明日志格式。对 value 部分,仅支持字符串。如果是以`$`开头,则表明是要获取 [Nginx 
内置变量](http://nginx.org/en/docs/varindex.html)。特别的,该设置是全局生效的,意味着指定 log_format 
后,将对所有绑定 kafka-logger 的 Route 或 Service 生效。 |

Review comment:
       `该设置是全局生效的` can be set to bold, to highlight  this message.

##########
File path: t/plugin/kafka-logger.t
##########
@@ -722,3 +722,43 @@ GET /t
 [qr/partition_id: 1/,
 qr/partition_id: 0/,
 qr/partition_id: 2/]
+
+
+
+=== TEST 20: add plugin metadata

Review comment:
       Should add another test case to cover whether the `log_format` setting 
is effective.




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


Reply via email to