aboutsummaryrefslogtreecommitdiffstats
path: root/util/async.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-05-04 00:10:17 +0200
committerKim Alvefur <zash@zash.se>2018-05-04 00:10:17 +0200
commite3979fddddf4f4621a2509b9c933c1f7e24e1360 (patch)
tree59460617b20f0a1182bdec0b92b8c91370f787bf /util/async.lua
parent90f9911c535e8be954ec15d6042796bd91338e59 (diff)
downloadprosody-e3979fddddf4f4621a2509b9c933c1f7e24e1360.tar.gz
prosody-e3979fddddf4f4621a2509b9c933c1f7e24e1360.zip
util.async: Move runner id into log tag
Avoids string concatenation in every logger call
Diffstat (limited to 'util/async.lua')
-rw-r--r--util/async.lua9
1 files changed, 6 insertions, 3 deletions
diff --git a/util/async.lua b/util/async.lua
index e8be0510..46a64ecb 100644
--- a/util/async.lua
+++ b/util/async.lua
@@ -1,4 +1,5 @@
-local log = require "util.logger".init("util.async");
+local logger = require "util.logger";
+local log = logger.init("util.async");
local new_id = require "util.id".short;
local function checkthread()
@@ -135,8 +136,10 @@ local function default_error_watcher(runner, err)
end
local function default_func(f) f(); end
local function runner(func, watchers, data)
+ local id = new_id();
+ local _log = logger.init("runner" .. id);
return setmetatable({ func = func or default_func, thread = false, state = "ready", notified_state = "ready",
- queue = {}, watchers = watchers or { error = default_error_watcher }, data = data, id = new_id() }
+ queue = {}, watchers = watchers or { error = default_error_watcher }, data = data, id = id, _log = _log; }
, runner_mt);
end
@@ -219,7 +222,7 @@ function runner_mt:enqueue(input)
end
function runner_mt:log(level, fmt, ...)
- return log(level, "[runner %s] "..fmt, self.id, ...);
+ return self._log(level, fmt, ...);
end
function runner_mt:onready(f)