Software /
code /
prosody
Changeset
8788:7a9b680a79fb
util.async: Move runner id into log tag
Avoids string concatenation in every logger call
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 04 May 2018 00:10:17 +0200 |
parents | 8787:5dbebb7627ef |
children | 8794:0e2c1c4d4f78 |
files | util/async.lua |
diffstat | 1 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/util/async.lua Fri May 11 16:03:35 2018 +0200 +++ b/util/async.lua Fri May 04 00:10:17 2018 +0200 @@ -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 @@ 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 @@ 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)