# HG changeset patch # User Matthew Wild # Date 1442695706 -3600 # Node ID af7a51d78b7b3950c1135fbf9ac51cc3563fbcd7 # Parent b1fa55d170572b2d5972e58e897c5ede6c4fa264 client: Improve stream logging, now prefixed by client name (taken from script) diff -r b1fa55d17057 -r af7a51d78b7b scansion/objects/client.lua --- a/scansion/objects/client.lua Sat Sep 19 21:45:23 2015 +0100 +++ b/scansion/objects/client.lua Sat Sep 19 21:48:26 2015 +0100 @@ -26,18 +26,22 @@ return { _validate = function (client) assert(client.jid, "No JID specified"); - client.stream = verse.new(); - client.stream:hook("stanza", function (stanza) print("Stanza:", stanza) end); + client.stream = verse.new(verse.new_logger(client.name)); + + function client.log(fmt, ...) + return client.stream:info(fmt, ...); + end -- This one prints all received data - client.stream:hook("incoming-raw", print, 1000); - client.stream:hook("outgoing-raw", print, 1000); - + client.stream:hook("incoming-raw", function (s) client.log("Data in: %s", s); end, 1000); + client.stream:hook("outgoing-raw", function (s) client.log("Data out: %s", s); end, 1000); + -- And incoming, parsed, stanzas + client.stream:hook("stanza", function (s) client.log("Stanza: %s", s) end); end; connects = function (client) local wait, done = async.waiter(); - client.stream:hook("ready", function () print"aha" done() end); + client.stream:hook("ready", function () client.log"ready" done() client.log("ready done") end); client.stream:connect_client(client.jid, client.password); wait(); client.full_jid = client.stream.jid; @@ -52,17 +56,19 @@ local expected_stanza = fill_vars(client.script, parse_xml(table.concat(data))); local function stanza_handler(received_stanza) if not stanzacmp.stanzas_match(expected_stanza, received_stanza) then - print("NOT IT!") verse.quit(); + client.log("NOT IT!") + client.log("Expected: %s", expected_stanza); + client.log("Received: %s", received_stanza); else - print("YES!") + client.log("YES! %s", expected_stanza) end expected_stanza = nil; end client.stream:hook("stanza", stanza_handler, 100); verse.add_task(stanza_timeout, function () if not expected_stanza then return; end - print("TIMEOUT") + client.log("TIMEOUT waiting for %s", expected_stanza) end); end;