mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-14 17:01:20 +08:00
feature: add option to include request body in log util (#1545)
This commit is contained in:
parent
6cf21d3c2f
commit
39ef6fb2eb
@ -36,6 +36,7 @@ local schema = {
|
||||
buffer_duration = {type = "integer", minimum = 1, default = 60},
|
||||
inactive_timeout = {type = "integer", minimum = 1, default = 5},
|
||||
batch_max_size = {type = "integer", minimum = 1, default = 1000},
|
||||
include_req_body = {type = "boolean", default = false}
|
||||
},
|
||||
required = {"uri"}
|
||||
}
|
||||
@ -121,7 +122,7 @@ end
|
||||
|
||||
|
||||
function _M.log(conf)
|
||||
local entry = log_util.get_full_log(ngx)
|
||||
local entry = log_util.get_full_log(ngx, conf)
|
||||
|
||||
if not entry.route_id then
|
||||
core.log.error("failed to obtain the route id for http logger")
|
||||
|
@ -44,6 +44,7 @@ local schema = {
|
||||
buffer_duration = {type = "integer", minimum = 1, default = 60},
|
||||
inactive_timeout = {type = "integer", minimum = 1, default = 5},
|
||||
batch_max_size = {type = "integer", minimum = 1, default = 1000},
|
||||
include_req_body = {type = "boolean", default = false}
|
||||
},
|
||||
required = {"broker_list", "kafka_topic", "key"}
|
||||
}
|
||||
@ -111,7 +112,7 @@ end
|
||||
|
||||
|
||||
function _M.log(conf)
|
||||
local entry = log_util.get_full_log(ngx)
|
||||
local entry = log_util.get_full_log(ngx, conf)
|
||||
|
||||
if not entry.route_id then
|
||||
core.log.error("failed to obtain the route id for kafka logger")
|
||||
|
@ -42,6 +42,7 @@ local schema = {
|
||||
tls = {type = "boolean", default = false},
|
||||
batch_max_size = {type = "integer", minimum = 1, default = 1000},
|
||||
buffer_duration = {type = "integer", minimum = 1, default = 60},
|
||||
include_req_body = {type = "boolean", default = false}
|
||||
},
|
||||
required = {"host", "port"}
|
||||
}
|
||||
@ -127,7 +128,7 @@ end
|
||||
|
||||
-- log phase in APISIX
|
||||
function _M.log(conf)
|
||||
local entry = log_util.get_full_log(ngx)
|
||||
local entry = log_util.get_full_log(ngx, conf)
|
||||
|
||||
if not entry.route_id then
|
||||
core.log.error("failed to obtain the route id for sys logger")
|
||||
|
@ -40,6 +40,7 @@ local schema = {
|
||||
buffer_duration = {type = "integer", minimum = 1, default = 60},
|
||||
inactive_timeout = {type = "integer", minimum = 1, default = 5},
|
||||
batch_max_size = {type = "integer", minimum = 1, default = 1000},
|
||||
include_req_body = {type = "boolean", default = false}
|
||||
},
|
||||
required = {"host", "port"}
|
||||
}
|
||||
@ -115,7 +116,7 @@ end
|
||||
|
||||
|
||||
function _M.log(conf)
|
||||
local entry = log_util.get_full_log(ngx)
|
||||
local entry = log_util.get_full_log(ngx, conf)
|
||||
|
||||
if not entry.route_id then
|
||||
core.log.error("failed to obtain the route id for tcp logger")
|
||||
|
@ -36,6 +36,7 @@ local schema = {
|
||||
buffer_duration = {type = "integer", minimum = 1, default = 60},
|
||||
inactive_timeout = {type = "integer", minimum = 1, default = 5},
|
||||
batch_max_size = {type = "integer", minimum = 1, default = 1000},
|
||||
include_req_body = {type = "boolean", default = false}
|
||||
},
|
||||
required = {"host", "port"}
|
||||
}
|
||||
@ -98,7 +99,7 @@ end
|
||||
|
||||
|
||||
function _M.log(conf)
|
||||
local entry = log_util.get_full_log(ngx)
|
||||
local entry = log_util.get_full_log(ngx, conf)
|
||||
|
||||
if not entry.route_id then
|
||||
core.log.error("failed to obtain the route id for udp logger")
|
||||
|
@ -18,7 +18,7 @@ local core = require("apisix.core")
|
||||
|
||||
local _M = {}
|
||||
|
||||
local function get_full_log(ngx)
|
||||
local function get_full_log(ngx, conf)
|
||||
local ctx = ngx.ctx.api_ctx
|
||||
local var = ctx.var
|
||||
local service_id
|
||||
@ -34,7 +34,7 @@ local function get_full_log(ngx)
|
||||
service_id = var.host
|
||||
end
|
||||
|
||||
return {
|
||||
local log = {
|
||||
request = {
|
||||
url = url,
|
||||
uri = var.request_uri,
|
||||
@ -56,6 +56,20 @@ local function get_full_log(ngx)
|
||||
start_time = ngx.req.start_time() * 1000,
|
||||
latency = (ngx.now() - ngx.req.start_time()) * 1000
|
||||
}
|
||||
|
||||
if conf.include_req_body then
|
||||
local body = ngx.req.get_body_data()
|
||||
if body then
|
||||
log.request.body = body
|
||||
else
|
||||
local body_file = ngx.req.get_body_file()
|
||||
if body_file then
|
||||
log.request.body_file = body_file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return log
|
||||
end
|
||||
|
||||
_M.get_full_log = get_full_log
|
||||
|
Loading…
Reference in New Issue
Block a user