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/18 08:17:45 UTC

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

liangliang4ward opened a new issue #6656:
URL: https://github.com/apache/apisix/issues/6656


   ### Description
   
   at clickhouse-logger-plugin.md describe custom log format.
   but when use default log format the docs may not given table demo.  
   
   use curtom log may lose some information. 
   


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



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

Posted by GitBox <gi...@apache.org>.
spacewander edited a comment on issue #6656:
URL: https://github.com/apache/apisix/issues/6656#issuecomment-1074671044


   The code can be anywhere which will be executed, like https://github.com/apache/apisix/blob/d1d8a8e4bbf81bbabc1127de998aaffce3ec3ed6/apisix/stream/plugins/mqtt-proxy.lua#L26
   You can put it in a custom plugin.


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



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

Posted by GitBox <gi...@apache.org>.
liangliang4ward commented on issue #6656:
URL: https://github.com/apache/apisix/issues/6656#issuecomment-1073785641


   hi, what about this? @spacewander 
   
   ```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



[GitHub] [apisix] spacewander commented on issue #6656: feat: clickhouse-logger-plugin may not support default log format

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #6656:
URL: https://github.com/apache/apisix/issues/6656#issuecomment-1073938173


   You can register your own variable, like: https://github.com/apache/apisix/blob/master/docs/en/latest/plugin-develop.md#register-custom-variable
   and https://github.com/apache/apisix/commit/b8b2a0fc194aa152b2afc31534a112f2a2de2c68


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



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

Posted by GitBox <gi...@apache.org>.
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



[GitHub] [apisix] spacewander commented on issue #6656: feat: clickhouse-logger-plugin may not support default log format

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #6656:
URL: https://github.com/apache/apisix/issues/6656#issuecomment-1072330584


   @zhendongcmss 
   What's your opinion?


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



[GitHub] [apisix] spacewander commented on issue #6656: feat: clickhouse-logger-plugin may not support default log format

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #6656:
URL: https://github.com/apache/apisix/issues/6656#issuecomment-1072330584


   @zhendongcmss 
   What's your opinion?


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



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

Posted by GitBox <gi...@apache.org>.
liangliang4ward commented on issue #6656:
URL: https://github.com/apache/apisix/issues/6656#issuecomment-1073395240


   maby we should use anthoer method to get property from full_log.
   


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



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

Posted by GitBox <gi...@apache.org>.
liangliang4ward commented on issue #6656:
URL: https://github.com/apache/apisix/issues/6656#issuecomment-1074581741


   > You can register your own variable, like: https://github.com/apache/apisix/blob/master/docs/en/latest/plugin-develop.md#register-custom-variable and [b8b2a0f](https://github.com/apache/apisix/commit/b8b2a0fc194aa152b2afc31534a112f2a2de2c68)
   
   edit code to register variable? Which file does that code go into?


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



[GitHub] [apisix] spacewander commented on issue #6656: feat: clickhouse-logger-plugin may not support default log format

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #6656:
URL: https://github.com/apache/apisix/issues/6656#issuecomment-1074671044


   The code can be anywhere which will be executed, like https://github.com/apache/apisix/blob/d1d8a8e4bbf81bbabc1127de998aaffce3ec3ed6/apisix/stream/plugins/mqtt-proxy.lua#L26


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