Diff

mod_log_json/mod_log_json.lua @ 4462:4356088ad675

mod_log_json: allow logging of formatted message This is for logging pipelines which can not or do not want to interpret sprintf-style strings but still need the complete string for search or whatever.
author Jonas Schäfer <jonas@wielicki.name>
date Mon, 22 Feb 2021 16:08:55 +0100
parent 3758:900ea02ab00b
child 4974:807007913f67
line wrap: on
line diff
--- a/mod_log_json/mod_log_json.lua	Mon Feb 22 17:56:27 2021 +0100
+++ b/mod_log_json/mod_log_json.lua	Mon Feb 22 16:08:55 2021 +0100
@@ -21,6 +21,8 @@
 			conn:send(payload);
 		end
 	end
+	local format = require "util.format".format;
+	local do_format = config.formatted_as or false;
 	return function (source, level, message, ...)
 		local args = pack(...);
 		for i = 1, args.n do
@@ -38,6 +40,9 @@
 			message = message,
 			args = array(args);
 		};
+		if do_format then
+			payload[do_format] = format(message, ...)
+		end
 		send(json.encode(payload));
 	end
 end