Kong: how can i add response header ("x_cache_status") in log_format

Created on 16 Oct 2020  ·  5Comments  ·  Source: Kong/kong

kong version: 1.3.0

this is my config:

log_format main '{"remote":"$remote_addr","user":"$remote_user","agent":"$http_user_agent","code":"$status","host":"$host","hostname":"$hostname","method":"$request_method","path":"$request_uri","port":"$remote_port","protocol":"$server_protocol","x_forwarded_for":"$http_x_forwarded_for","referer":"$http_referer","remote":"$remote_addr","request_length":"$request_length","request_time":$request_time,"scheme":"$scheme","server_addr":"$server_addr","x-cache-status":"$upstream_http_x_cache_status",}';

Summary

i use kong plugin: proxy-cache, and it add response header "x_cache_status" ,i want to log it, but I cannot get it from $upstream_http_x_cache_status
, how to do , please help

Additional Details & Logs

  • Kong version (1.3.0 or 2.1.0)
  • Kong debug-level startup logs ($ kong start --vv)
  • Kong error logs (<KONG_PREFIX>/logs/error.log)
  • Kong configuration (the output of a GET request to Kong's Admin port - see
    https://docs.konghq.com/latest/admin-api/#retrieve-node-information)
  • Operating system
pending author feedback pluginproxy-cache

Most helpful comment

Hello,

The X-Cache-Status is generated by the proxy-cache plugin directly, therefore it is not found in any upstream returned headers.

Give $sent_http_ x_cache_status a try, it should work. (not tested)

See: https://nginx.org/en/docs/http/ngx_http_core_module.html#var_sent_http_

All 5 comments

image

$upstream_http_cache_status neither

Hello,

The X-Cache-Status is generated by the proxy-cache plugin directly, therefore it is not found in any upstream returned headers.

Give $sent_http_ x_cache_status a try, it should work. (not tested)

See: https://nginx.org/en/docs/http/ngx_http_core_module.html#var_sent_http_

Hello,

The X-Cache-Status is generated by the proxy-cache plugin directly, therefore it is not found in any upstream returned headers.

Give $sent_http_ x_cache_status a try, it should work. (not tested)

See: https://nginx.org/en/docs/http/ngx_http_core_module.html#var_sent_http_

thanks a lot!

solved

Was this page helpful?
0 / 5 - 0 ratings