spacewander commented on code in PR #6960:
URL: https://github.com/apache/apisix/pull/6960#discussion_r867484185


##########
apisix/stream/xrpc/runner.lua:
##########
@@ -70,9 +75,53 @@ local function put_req_ctx(session, ctx)
 end
 
 
+local function filter_logger(ctx, logger)
+    if not logger or not logger.filter or #logger.filter == 0 then
+        return false
+    end
+
+    local expr, err = expr.new(logger.filter)
+    if err then
+        core.log.error("failed to validate the 'filter' expression: ", err)
+        return false
+    end
+    return expr:eval(ctx)
+end
+
+
+local function run_log_plugin(ctx, logger)
+    local pkg_name = "apisix.stream.plugins." .. logger.name
+    local ok, plugin = pcall(require, pkg_name)
+    if not ok then
+        core.log.error("failed to load plugin [", plugin, "] err: ", plugin)
+        return
+    end
+
+    core.ctx.set_vars_meta(ctx)
+    ctx.conf_id = tostring(logger.conf)
+    ctx.conf_type = "xrpc-logger"

Review Comment:
   Can we run these once instead of per-logger?



##########
apisix/schema_def.lua:
##########
@@ -807,6 +807,28 @@ local xrpc_protocol_schema = {
             description = "protocol-specific configuration",
             type = "object",
         },
+        logger = {
+            type = "array",
+            items = {
+                properties = {
+                    name = {
+                        type = "string",
+                    },
+                    filter = {
+                        description = "log filter rules",

Review Comment:
   ```suggestion
                           description = "logger filter rules",
   ```



##########
apisix/stream/xrpc/runner.lua:
##########
@@ -70,10 +74,54 @@ local function put_req_ctx(session, ctx)
 end
 
 
+local function log_filter(session, ctx)
+    local logger = session._route.protocol.logger
+    if not logger or not logger.filter or #logger.filter == 0 then
+        return false
+    end
+
+    local expr, err = expr.new(logger.filter)
+    if err then
+        core.log.error("failed to validate the 'filter' expression: ", err)
+        return false
+    end
+    return expr:eval(ctx)
+end
+
+
+local function run_log_plugin(session, ctx)
+    local logger = session._route.protocol.logger
+
+    local pkg_name = "apisix.stream.plugins." .. logger.name
+    local ok, plugin = pcall(require, pkg_name)
+
+    core.ctx.set_vars_meta(ctx)
+    ctx.conf_id = tostring(logger.conf)
+    ctx.conf_type = "xrpc-logger"
+
+    if not ok then
+        core.log.error("failed to load plugin [", plugin, "] err: ", plugin)

Review Comment:
   Missing this one?



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