This is an automated email from the ASF dual-hosted git repository. membphis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push: new f2f5ab9 feat: support `json` encoding escape for access logs (#2269) f2f5ab9 is described below commit f2f5ab97663805509baf3355c37336ffa557b68c Author: YuanSheng Wang <membp...@gmail.com> AuthorDate: Fri Oct 30 16:07:24 2020 +0800 feat: support `json` encoding escape for access logs (#2269) fix #2266 . --- .travis/apisix_cli_test.sh | 31 +++++++++++++++++++++++++++++++ bin/apisix | 2 +- conf/config-default.yaml | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.travis/apisix_cli_test.sh b/.travis/apisix_cli_test.sh index 091ff92..5f88ecd 100755 --- a/.travis/apisix_cli_test.sh +++ b/.travis/apisix_cli_test.sh @@ -441,3 +441,34 @@ if [ $count -ne 1 ]; then fi echo "passed: using env to set worker processes" + +# access log with JSON format + +echo ' +nginx_config: + http: + access_log_format: |- + {"@timestamp": "$time_iso8601", "client_ip": "$remote_addr", "status": "$status"} + access_log_format_escape: json +' > conf/config.yaml + +make init +make run +sleep 0.1 +curl http://127.0.0.1:9080/hello2 +sleep 4 +tail -n 1 logs/access.log > output.log + +if [ `grep -c '"client_ip": "127.0.0.1"' output.log` -eq '0' ]; then + echo "failed: invalid JSON log in access log" + exit 1 +fi + +if [ `grep -c 'main escape=json' conf/nginx.conf` -eq '0' ]; then + echo "failed: not found \"escape=json\" in conf/nginx.conf" + exit 1 +fi + +make stop + +echo "passed: access log with JSON format" diff --git a/bin/apisix b/bin/apisix index 2e72a31..d600d2b 100755 --- a/bin/apisix +++ b/bin/apisix @@ -239,7 +239,7 @@ http { lua_regex_match_limit 100000; lua_regex_cache_max_entries 8192; - log_format main '{* http.access_log_format *}'; + log_format main escape={* http.access_log_format_escape *} '{* http.access_log_format *}'; access_log {* http.access_log *} main buffer=16384 flush=3; open_file_cache max=1000 inactive=60; diff --git a/conf/config-default.yaml b/conf/config-default.yaml index ef9331f..f94bda9 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -126,6 +126,7 @@ nginx_config: # config for render the template to genarate n http: access_log: "logs/access.log" access_log_format: "$remote_addr - $remote_user [$time_local] $http_host \"$request\" $status $body_bytes_sent $request_time \"$http_referer\" \"$http_user_agent\" $upstream_addr $upstream_status $upstream_response_time" + access_log_format_escape: default # allows setting json or default characters escaping in variables keepalive_timeout: 60s # timeout during which a keep-alive client connection will stay open on the server side. client_header_timeout: 60s # timeout for reading client request header, then 408 (Request Time-out) error is returned to the client client_body_timeout: 60s # timeout for reading client request body, then 408 (Request Time-out) error is returned to the client