Browse Source

Added APICAST_PAYLOAD_BASE64 environment variable to switch base64 encoding of the request-response payload. By default it gets set to 'true'. If the payload needs to be logged in plain-text readbale format assuming its in simple XML/JSON/Text format, then the flag needs to be set to 'false'.

pull/1/head
Satish K. Pagare 8 years ago
parent
commit
acf1498127
  1. 20
      verbose.lua

20
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
request["body"] = ngx.encode_base64(ngx.var.request_body) if (base64_flag == 'true') then
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()
request["raw"] = ngx.encode_base64(ngx.req.raw_header()) if (base64_flag == 'true') then
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
response["body"] = ngx.encode_base64(ngx.ctx.buffered) if (base64_flag == 'true') then
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