@@ -40,9 +40,23 @@ function _M.new(config)
4040 end
4141
4242 self .enable_access_logs_val = val_for_ngx_var [enable_access_logs ]
43- self .custom_logging = config .custom_logging
4443 self .enable_json_logs = config .enable_json_logs
45- self .json_object_config = config .json_object_config or {}
44+
45+ if config .custom_logging then
46+ self .custom_logging_template = TemplateString .new (config .custom_logging , " liquid" )
47+ end
48+
49+ if self .enable_json_logs then
50+ self .json_object_config = {}
51+
52+ for _ , entry in ipairs (config .json_object_config or {}) do
53+ self .json_object_config [# self .json_object_config + 1 ] = {
54+ key = entry .key ,
55+ template = TemplateString .new (
56+ entry .value , entry .value_type or default_template_type )
57+ }
58+ end
59+ end
4660
4761 self :load_condition (config )
4862
99113--- log_dump_json: returns an string with the json output.
100114local function log_dump_json (self , extended_context )
101115 local result = {}
102- for _ , value in ipairs (self .json_object_config ) do
103- result [value .key ] = TemplateString . new ( value . value , value . value_type or default_template_type ) :render (extended_context )
116+ for _ , entry in ipairs (self .json_object_config ) do
117+ result [entry .key ] = entry . template :render (extended_context )
104118 end
105119
106120 local status , data = pcall (cjson .encode , result )
116130
117131-- log_dump_line: render the liquid custom_logging value and return it.
118132local function log_dump_line (self , extended_context )
119- local tmpl = TemplateString .new (self .custom_logging , " liquid" )
120- return tmpl :render (extended_context )
133+ return self .custom_logging_template :render (extended_context )
121134end
122135
123136-- get_log_line return the log line based on the kind of log defined in the
132145
133146
134147function _M :use_default_access_logs ()
135- return not (self .custom_logging or self .enable_json_logs )
148+ return not (self .custom_logging_template or self .enable_json_logs )
136149end
137150
138151function _M :log (context )
0 commit comments