In some scenarios it will be required to either change the default Apigee Router/Nginx log format or add additional variables. This article explains how to update the default Apigee Router/Nginx log format configuration.
1. Create router.properties file at the below path if that does not exist:
File path: /opt/apigee/customer/application/router.properties
2. Add following content to the /opt/apigee/customer/application/router.properties file for adding a new log_format configuration with the name router_new. Update log_format value as required, the default log_format value and the list of Nginx variables can be found at [1], [2].
conf_load_balancing_load.balancing.driver.nginx.global.http.parameters.template.extra=log_format router_new '$time_iso8601\\\\t$hostname\\\\t$remote_addr:$remote_port\\\\t'\\\\n\\n '$upstream_addr\\\\t$request_time\\\\t-\\\\t-\\\\t'\\\\n\\n '$status\\\\t$upstream_status\\\\t$request_length\\\\t'\\\\n\\n '$body_bytes_sent\\\\t'\\\\n\\n '$request\\\\t$upstream_http_x_apigee_message_id\\\\t'\\\\n\\n '$http_user_agent\\\\t$host\\t$hostname-$pid-$connection-$connection_requests\\\\t$my_nginx_var_xff\\t'\\\\n\\n '$upstream_http_x_apigee_fault_flag\\\\t$upstream_http_x_apigee_fault_source\\\\t$upstream_http_x_apigee_fault_code\\\\t'\\\\n\\n '$upstream_http_x_apigee_fault_policy\\t$upstream_http_x_apigee_fault_flow\\t$upstream_http_x_apigee_fault_revision\\t'\\\\n\\n '$upstream_http_x_apigee_dp_color\\\\t$my_x_apigee_target_latency\\\\t'\\\\n\\n '$upstream_http_x_apigee_proxy\\\\t$upstream_http_x_apigee_proxy_basepath\\\\t'\\\\n\\n '$self_region\\\\t$self_pod\\\\t$self_color\\\\t$ssl_protocol\\\\t$ssl_client_verify\\\\t$ssl_session_id\\\\t$ssl_session_reused\\\\t$upstream_pod\\\\t$upstream_region';\\\\n\\n\n conf_load_balancing_load.balancing.driver.nginx.access.log=${conf_load_balancing_load.balancing.driver.nginx.log.dir}/${org}~${env}.${port}_access_log router_new
3. Restart the Router to apply the new configuration:
apigee-service edge-router restart
4. Check whether the new log_format configuration (router_new) was added to /opt/nginx/conf.d/0-default.conf file:
cat /opt/nginx/conf.d/0-default.conf | grep router_new -A 10
5. Send a collection of API requests to an API proxy and verify new log format in /opt/apigee/var/log/edge-router/nginx/${org}~${env}.${port}_access_log file.
[1] The default log_format configuration value can be found in the below file:
/opt/apigee/edge-router/conf/load_balancing.properties
\nlog_format router '$time_iso8601\\t$hostname\\t$remote_addr:$remote_port\\t'\\n '$upstream_addr\\t$request_time\\t-\\t-\\t'\\n '$status\\t$upstream_status\\t$request_length\\t'\\n '$body_bytes_sent\\t'\\n '$request\\t$upstream_http_x_apigee_message_id\\t'\\n '$http_user_agent\\t$host\\t$hostname-$pid-$connection-$connection_requests\\t$my_nginx_var_xff\\t'\\n '$upstream_http_x_apigee_fault_flag\\t$upstream_http_x_apigee_fault_source\\t$upstream_http_x_apigee_fault_code\\t'\\n '$upstream_http_x_apigee_fault_policy\\t$upstream_http_x_apigee_fault_flow\\t$upstream_http_x_apigee_fault_revision\\t'\\n '$upstream_http_x_apigee_dp_color\\t$my_x_apigee_target_latency\\t'\\n '$upstream_http_x_apigee_proxy\\t$upstream_http_x_apigee_proxy_basepath\\t'\\n '$self_region\\t$self_pod\\t$self_color\\t$ssl_protocol\\t$upstream_pod\\t$upstream_region\\t'\\n '$upstream_org\\t$upstream_env\\t$my_nginx_var_proto\\t$upstream_http_x_apigee_nat';\\n\\n
[2] The list of Nginx variables can be found below:
http://nginx.org/en/docs/varindex.html
[3] HTTP request and response headers can also be added to the log using $http_{request_header_name} and $upstream_http_{response_header_name} formats:
https://community.apigee.com/articles/53806/how-to-add-request-headers-to-apigee-ngnix-access.html