Mercurial > prosody-modules
annotate mod_log_json/mod_log_json.lua @ 4515:2e33eeafe962
mod_muc_markers: Prevent any markers from reaching the archive, even if untracked
Original intention was to leave alone things that this module isn't
handling. However markers in archives are just problematic without
more advanced logic about what is markable and what is not. It also
requires a more advanced query in mod_muc_rai to determine the latest
markable message instead of the latest archived message.
I'd rather keep the "is archivable" and "is markable" definition the
same for simplicity. I don't want to introduce yet another set of rules
for no reason.
No markers in MAM.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 22 Mar 2021 15:55:02 +0000 |
| parents | 4356088ad675 |
| children | 807007913f67 |
| rev | line source |
|---|---|
| 3732 | 1 local pack = require "util.table".pack; |
| 2 local json = require "util.json"; | |
| 3 local array = require "util.array"; | |
| 4 local datetime = require "util.datetime".datetime; | |
| 3746 | 5 local socket = require "socket"; |
| 3732 | 6 |
| 7 module:set_global(); | |
| 8 | |
| 9 local function sink_maker(config) | |
| 3746 | 10 local send = function () end |
| 11 if config.filename then | |
| 12 local logfile = io.open(config.filename, "a+"); | |
| 13 logfile:setvbuf("no"); | |
| 14 function send(payload) | |
| 15 logfile:write(payload, "\n"); | |
| 16 end | |
| 17 elseif config.udp_host and config.udp_port then | |
| 18 local conn = socket.udp(); | |
|
3748
27abf3b6819a
mod_log_json: Use correct method to specify remote endpoint
Kim Alvefur <zash@zash.se>
parents:
3747
diff
changeset
|
19 conn:setpeername(config.udp_host, config.udp_port); |
| 3746 | 20 function send(payload) |
| 21 conn:send(payload); | |
| 22 end | |
| 23 end | |
|
4462
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
24 local format = require "util.format".format; |
|
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
25 local do_format = config.formatted_as or false; |
| 3732 | 26 return function (source, level, message, ...) |
| 27 local args = pack(...); | |
| 28 for i = 1, args.n do | |
| 29 if args[i] == nil then | |
| 30 args[i] = json.null; | |
| 31 elseif type(args[i]) ~= "string" or type(args[i]) ~= "number" then | |
| 32 args[i] = tostring(args[i]); | |
| 33 end | |
| 34 end | |
| 35 args.n = nil; | |
| 36 local payload = { | |
| 37 datetime = datetime(), | |
| 38 source = source, | |
| 39 level = level, | |
| 40 message = message, | |
| 41 args = array(args); | |
| 42 }; | |
|
4462
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
43 if do_format then |
|
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
44 payload[do_format] = format(message, ...) |
|
4356088ad675
mod_log_json: allow logging of formatted message
Jonas Schäfer <jonas@wielicki.name>
parents:
3758
diff
changeset
|
45 end |
| 3746 | 46 send(json.encode(payload)); |
| 3732 | 47 end |
| 48 end | |
| 49 | |
|
3758
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
50 function module.unload() |
|
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
51 -- deregister |
|
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
52 require"core.loggingmanager".register_sink_type("json", nil); |
|
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
53 end |
|
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
54 |
| 3732 | 55 require"core.loggingmanager".register_sink_type("json", sink_maker); |
