Software /
code /
prosody-modules
Changeset
5585:5b316088bef5
mod_rest: Use logger of HTTP request in trunk
In Prosody trunk rev c975dafa4303 each HTTP request gained its own log
sink, to make it easy to log things related to each request and group
those messages. Especially where async is used, spreading the request
and response apart as mod_rest does with iq stanzas, this grouped
logging should help find related messages.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 07 Jul 2023 00:10:37 +0200 |
parents | 5584:2ac5f459e097 |
children | 5586:30b9f78b5058 |
files | mod_rest/mod_rest.lua |
diffstat | 1 files changed, 7 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua Fri Jun 30 23:58:03 2023 +0200 +++ b/mod_rest/mod_rest.lua Fri Jul 07 00:10:37 2023 +0200 @@ -294,6 +294,7 @@ local function handle_request(event, path) local request, response = event.request, event.response; + local log = request.log or module._log; local from; local origin; local echo = path == "echo"; @@ -310,7 +311,7 @@ from = jid.join(origin.username, origin.host, origin.resource); origin.full_jid = from; origin.type = "c2s"; - origin.log = module._log; + origin.log = log; end local payload, err = parse_request(request, path); if not payload then @@ -353,7 +354,7 @@ ["xml:lang"] = payload.attr["xml:lang"], }; - module:log("debug", "Received[rest]: %s", payload:top_tag()); + log("debug", "Received[rest]: %s", payload:top_tag()); local send_type = decide_type((request.headers.accept or "") ..",".. (request.headers.content_type or ""), supported_outputs) if echo then @@ -396,7 +397,7 @@ local p = module:send_iq(payload, origin, iq_timeout):next( function (result) - module:log("debug", "Sending[rest]: %s", result.stanza:top_tag()); + log("debug", "Sending[rest]: %s", result.stanza:top_tag()); response.headers.content_type = send_type; if responses[1] then local tail = responses[#responses]; @@ -411,11 +412,11 @@ end, function (error) if not errors.is_err(error) then - module:log("error", "Uncaught native error: %s", error); + log("error", "Uncaught native error: %s", error); return select(2, errors.coerce(nil, error)); elseif error.context and error.context.stanza then response.headers.content_type = send_type; - module:log("debug", "Sending[rest]: %s", error.context.stanza:top_tag()); + log("debug", "Sending[rest]: %s", error.context.stanza:top_tag()); return encode(send_type, error.context.stanza); else return error; @@ -431,7 +432,7 @@ return p; else function origin.send(stanza) - module:log("debug", "Sending[rest]: %s", stanza:top_tag()); + log("debug", "Sending[rest]: %s", stanza:top_tag()); response.headers.content_type = send_type; response:send(encode(send_type, stanza)); return true;