aboutsummaryrefslogtreecommitdiffstats
path: root/util/logger.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2008-12-06 23:13:38 +0000
committerMatthew Wild <mwild1@gmail.com>2008-12-06 23:13:38 +0000
commitbf7d712864d75ef280371ffb9fdca39e51d32405 (patch)
tree9bce18e600f1bdef5e1b027f90295feb7540e759 /util/logger.lua
parent1142f3083841c09f814c3a524d463e5d042f0a56 (diff)
downloadprosody-bf7d712864d75ef280371ffb9fdca39e51d32405.tar.gz
prosody-bf7d712864d75ef280371ffb9fdca39e51d32405.zip
Make it possible to set custom output handler for logger
Diffstat (limited to 'util/logger.lua')
-rw-r--r--util/logger.lua18
1 files changed, 15 insertions, 3 deletions
diff --git a/util/logger.lua b/util/logger.lua
index 82a7e110..f7ea187b 100644
--- a/util/logger.lua
+++ b/util/logger.lua
@@ -17,11 +17,9 @@
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
--
-
-
local format, rep = string.format, string.rep;
local io_write = io.write;
-local print = print;
+local pcall = pcall;
local debug = debug;
local tostring = tostring;
local math_max = math.max;
@@ -42,6 +40,8 @@ end
local sourcewidth = 20;
+local outfunction = nil;
+
function init(name)
--name = nil; -- While this line is not commented, will automatically fill in file/line number info
sourcewidth = math_max(#name+2, sourcewidth);
@@ -51,6 +51,9 @@ function init(name)
local inf = debug.getinfo(3, 'Snl');
level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline;
end
+
+ if outfunction then return outfunction(name, level, message, ...); end
+
if ... then
io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", format(message, ...), "\n");
else
@@ -59,4 +62,13 @@ function init(name)
end
end
+function setwriter(f)
+ if not f then outfunction = nil; return true, nil; end
+ local ok, ret = pcall(f, "logger", "info", "Switched logging output successfully");
+ if ok then
+ outfunction = f;
+ end
+ return ok, ret;
+end
+
return _M;