Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Performance
- Camel Policy: avoid unnecessary closure allocation per request [PR #1584](https://github.com/3scale/APIcast/pull/1584)
- Logging Policy: construct all templates at init time [PR #1587](https://github.com/3scale/APIcast/pull/1587)

### Fixed
- Correct FAPI header to `x-fapi-interaction-id` [PR #1557](https://github.com/3scale/APIcast/pull/1557) [THREESCALE-11957](https://issues.redhat.com/browse/THREESCALE-11957)
Expand Down
27 changes: 20 additions & 7 deletions gateway/src/apicast/policy/logging/logging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,23 @@ function _M.new(config)
end

self.enable_access_logs_val = val_for_ngx_var[enable_access_logs]
self.custom_logging = config.custom_logging
self.enable_json_logs = config.enable_json_logs
self.json_object_config = config.json_object_config or {}

if config.custom_logging then
self.custom_logging_template = TemplateString.new(config.custom_logging, "liquid")
end

if self.enable_json_logs then
self.json_object_config = {}

for _, entry in ipairs(config.json_object_config or {}) do
self.json_object_config[#self.json_object_config+1] = {
key = entry.key,
template = TemplateString.new(
entry.value, entry.value_type or default_template_type)
}
end
end

self:load_condition(config)

Expand Down Expand Up @@ -99,8 +113,8 @@ end
--- log_dump_json: returns an string with the json output.
local function log_dump_json(self, extended_context)
local result = {}
for _, value in ipairs(self.json_object_config) do
result[value.key] = TemplateString.new(value.value, value.value_type or default_template_type):render(extended_context)
for _, entry in ipairs(self.json_object_config) do
result[entry.key] = entry.template:render(extended_context)
end

local status, data = pcall(cjson.encode, result)
Expand All @@ -116,8 +130,7 @@ end

-- log_dump_line: render the liquid custom_logging value and return it.
local function log_dump_line(self, extended_context)
local tmpl = TemplateString.new(self.custom_logging, "liquid")
return tmpl:render(extended_context)
return self.custom_logging_template:render(extended_context)
end

-- get_log_line return the log line based on the kind of log defined in the
Expand All @@ -132,7 +145,7 @@ end


function _M:use_default_access_logs()
return not (self.custom_logging or self.enable_json_logs)
return not (self.custom_logging_template or self.enable_json_logs)
end

function _M:log(context)
Expand Down
Loading