Browse Source

Merge branch 'master' of github.com:nmasse-itix/apicast-logger

master
Nicolas Massé 8 years ago
parent
commit
51b0956c25
  1. 5
      README.md
  2. 14
      verbose.lua

5
README.md

@ -188,6 +188,11 @@ export SYSLOG_PROTOCOL=tcp
export APICAST_MODULE=custom/verbose export APICAST_MODULE=custom/verbose
``` ```
Plain text logging of payload without base64 encoding:
```
export APICAST_PAYLOAD_BASE64=false
```
Then, you need to register a resolver in the nginx configuration (example using the Google DNS): Then, you need to register a resolver in the nginx configuration (example using the Google DNS):
``` ```
cat <<EOF > apicast/apicast.d/resolver.conf cat <<EOF > apicast/apicast.d/resolver.conf

14
verbose.lua

@ -27,6 +27,7 @@ function _M:init()
host = os.getenv('SYSLOG_HOST') host = os.getenv('SYSLOG_HOST')
port = os.getenv('SYSLOG_PORT') port = os.getenv('SYSLOG_PORT')
proto = os.getenv('SYSLOG_PROTOCOL') or 'tcp' proto = os.getenv('SYSLOG_PROTOCOL') or 'tcp'
base64_flag = os.getenv('APICAST_PAYLOAD_BASE64') or 'true'
flush_limit = os.getenv('SYSLOG_FLUSH_LIMIT') or '0' flush_limit = os.getenv('SYSLOG_FLUSH_LIMIT') or '0'
periodic_flush = os.getenv('SYSLOG_PERIODIC_FLUSH') or '5' periodic_flush = os.getenv('SYSLOG_PERIODIC_FLUSH') or '5'
drop_limit = os.getenv('SYSLOG_DROP_LIMIT') or '1048576' drop_limit = os.getenv('SYSLOG_DROP_LIMIT') or '1048576'
@ -103,12 +104,21 @@ function _M.body_filter()
-- Gather information of the request -- Gather information of the request
local request = {} local request = {}
if ngx.var.request_body then if ngx.var.request_body then
if (base64_flag == 'true') then
request["body"] = ngx.encode_base64(ngx.var.request_body) request["body"] = ngx.encode_base64(ngx.var.request_body)
else
request["body"] = ngx.var.request_body
end
end end
request["headers"] = ngx.req.get_headers() request["headers"] = ngx.req.get_headers()
request["start_time"] = ngx.req.start_time() request["start_time"] = ngx.req.start_time()
request["http_version"] = ngx.req.http_version() request["http_version"] = ngx.req.http_version()
if (base64_flag == 'true') then
request["raw"] = ngx.encode_base64(ngx.req.raw_header()) request["raw"] = ngx.encode_base64(ngx.req.raw_header())
else
request["raw"] = ngx.req.raw_header()
end
request["method"] = ngx.req.get_method() request["method"] = ngx.req.get_method()
request["uri_args"] = ngx.req.get_uri_args() request["uri_args"] = ngx.req.get_uri_args()
request["request_id"] = ngx.var.request_id request["request_id"] = ngx.var.request_id
@ -117,7 +127,11 @@ function _M.body_filter()
-- Gather information of the response -- Gather information of the response
local response = {} local response = {}
if ngx.ctx.buffered then if ngx.ctx.buffered then
if (base64_flag == 'true') then
response["body"] = ngx.encode_base64(ngx.ctx.buffered) response["body"] = ngx.encode_base64(ngx.ctx.buffered)
else
response["body"] = ngx.ctx.buffered
end
end end
response["headers"] = ngx.resp.get_headers() response["headers"] = ngx.resp.get_headers()
response["status"] = ngx.status response["status"] = ngx.status

Loading…
Cancel
Save