Custom Access logs format

Greetings!

I would like to create my own log_format for all access logs. But I’m trying to find a way to do it without having to create my own kong image.

I tried creating a ConfigMap of nginx.conf and adding my own log_format in it… But nginx is having a hard time with chown:

chown: /usr/local/kong/nginx.conf: Read-only file system

For NGINX Ingress controller, it is possible to be done using the ConfigMap nginx-configuration and the data: log-format-upstream

Any recommendation?

Thanks,
Sartigan

I know there is a way to log it as a JSON structure:

json_combined arg

Not sure if thats what you were thinking about doing.

My question is about adding such configuration using kong’s official image without creating a custom kong image using a Dockerfile and copying my own custom-nginx.template.

The easy solution would be to just create my own custom image… but… I dont want to create a new image every time there is a new version of kong. I want to keep using the official image and inject my own log format

They have had an active effort to allow env variables to inject and enable dynamic configurations of all this to reduce the need for custom templates. I don’t think that specific argument needed on the logs is currently like that though as it has not been highly needed like many other template fields. I am sure they would appreciate a PR could be done to enable customizing it though.

I use KONG_NGINX_HTTP_LOG_FORMAT to customize the log format in our ECS deployment. Haven’t tried that in kubernetes.

ENV KONG_PROXY_ACCESS_LOG=’/dev/stdout custom_fmt’
ENV KONG_ADMIN_ACCESS_LOG=’/dev/stdout custom_fmt’
ENV KONG_NGINX_HTTP_LOG_FORMAT=“custom_fmt '[$time_local] [info] SN=Kong CI=$http_pf_correlation_id
HRU=”$request" HSC=$status ET=$request_time IP=$remote_addr HCL=$body_bytes_sent
“$http_referer” “$http_user_agent”’"

1 Like

Unfortunately, those Env vars didn’t work with kong:1.3

Thanks it worked perfectly !!!


© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ