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 2022/03/21 11:32:09 UTC

[GitHub] [apisix] liangliang4ward edited a comment on issue #6656: feat: clickhouse-logger-plugin may not support default log format

liangliang4ward edited a comment on issue #6656:
URL: https://github.com/apache/apisix/issues/6656#issuecomment-1073785641


   hi, what about this? @spacewander 
   this code just for test.
   
   ```lua
   local function get_custom_format_log2(ctx,format,conf,ngx)
       local log_format = lru_log_format(format or "", nil, gen_log_format, format)
       local entry = core.table.new(0, core.table.nkeys(log_format))
       local full_log = get_full_log(ngx,conf)
       for k, var_attr in pairs(log_format) do
           if var_attr[1] then
               entry[k] = ctx.var[var_attr[2]]
           elseif var_attr[2]:byte(1,1) == str_byte("#") then
               local res = ngx_re.split(var_attr[2],"#");
               local tempVal = full_log;
               for i = 2,#res do
                   if tempVal then
                       tempVal = tempVal[res[i]]
                   else
                       tempVal = nil
                   end
               end
               if type(tempVal) == "table" then
                   entry[k] = core.json.encode(tempVal);
               else
                   entry[k] = tempVal;
               end
           else
               entry[k] = var_attr[2]
           end
       end
   
       local matched_route = ctx.matched_route and ctx.matched_route.value
       if matched_route then
           entry.service_id = matched_route.service_id
           entry.route_id = matched_route.id
       end
       return entry
   
   end
   ```
   
   ```conf
   "log_format": {
           "host": "$host",
           "@timestamp": "$time_iso8601",
           "client_ip": "$remote_addr",
           "request_id":"#request#headers#x-request-id",
           "request_info":"#request"
   
       }
   ```


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