Software /
code /
prosody-modules
Comparison
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 |
comparison
equal
deleted
inserted
replaced
4461:b9c1216987ae | 4462:4356088ad675 |
---|---|
19 conn:setpeername(config.udp_host, config.udp_port); | 19 conn:setpeername(config.udp_host, config.udp_port); |
20 function send(payload) | 20 function send(payload) |
21 conn:send(payload); | 21 conn:send(payload); |
22 end | 22 end |
23 end | 23 end |
24 local format = require "util.format".format; | |
25 local do_format = config.formatted_as or false; | |
24 return function (source, level, message, ...) | 26 return function (source, level, message, ...) |
25 local args = pack(...); | 27 local args = pack(...); |
26 for i = 1, args.n do | 28 for i = 1, args.n do |
27 if args[i] == nil then | 29 if args[i] == nil then |
28 args[i] = json.null; | 30 args[i] = json.null; |
36 source = source, | 38 source = source, |
37 level = level, | 39 level = level, |
38 message = message, | 40 message = message, |
39 args = array(args); | 41 args = array(args); |
40 }; | 42 }; |
43 if do_format then | |
44 payload[do_format] = format(message, ...) | |
45 end | |
41 send(json.encode(payload)); | 46 send(json.encode(payload)); |
42 end | 47 end |
43 end | 48 end |
44 | 49 |
45 function module.unload() | 50 function module.unload() |