Mercurial > prosody-modules
annotate mod_log_json/mod_log_json.lua @ 3955:017f60608fc8
mod_smacks: also count outgoing MAM messages
mod_smacks doesn't count outgoing MAM messages, which causes warnings in Prosody such as:
> The client says it handled 41 new stanzas, but we only sent 2
It seems mod_smacks is in the wrong here and that it's too strict in trying to determine what is a valid stanza to count.
In RFC6120:
> Definition of XML Stanza: An XML stanza is the basic unit of meaning
> in XMPP. A stanza is a first-level element (at depth=1 of the stream)
> whose element name is "message", "presence", or "iq" and whose
> qualifying namespace is 'jabber:client' or 'jabber:server'.
author | JC Brand <jc@opkode.com> |
---|---|
date | Thu, 26 Mar 2020 11:57:02 +0100 |
parents | 900ea02ab00b |
children | 4356088ad675 |
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 | |
3732 | 24 return function (source, level, message, ...) |
25 local args = pack(...); | |
26 for i = 1, args.n do | |
27 if args[i] == nil then | |
28 args[i] = json.null; | |
29 elseif type(args[i]) ~= "string" or type(args[i]) ~= "number" then | |
30 args[i] = tostring(args[i]); | |
31 end | |
32 end | |
33 args.n = nil; | |
34 local payload = { | |
35 datetime = datetime(), | |
36 source = source, | |
37 level = level, | |
38 message = message, | |
39 args = array(args); | |
40 }; | |
3746 | 41 send(json.encode(payload)); |
3732 | 42 end |
43 end | |
44 | |
3758
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
45 function module.unload() |
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
46 -- deregister |
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
47 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
|
48 end |
900ea02ab00b
mod_log_json: Deregister log sink on unload
Kim Alvefur <zash@zash.se>
parents:
3748
diff
changeset
|
49 |
3732 | 50 require"core.loggingmanager".register_sink_type("json", sink_maker); |