mod_adhoc: Add support for commands only executable by global administrators
[prosody.git] / util / logger.lua
index 1fbd49779dcea8673d5a25208edb5d70a4333cae..c3bf399266703a6832e30ed14c6ab42183052c4e 100644 (file)
@@ -16,11 +16,7 @@ module "logger"
 local name_sinks, level_sinks = {}, {};
 local name_patterns = {};
 
--- Weak-keyed so that loggers are collected
-local modify_hooks = setmetatable({}, { __mode = "k" });
-
 local make_logger;
-local outfunction = nil;
 
 function init(name)
        local log_debug = make_logger(name, "debug");
@@ -31,8 +27,6 @@ function init(name)
        --name = nil; -- While this line is not commented, will automatically fill in file/line number info
        local namelen = #name;
        return function (level, message, ...)
-                       if outfunction then return outfunction(name, level, message, ...); end
-                       
                        if level == "debug" then
                                return log_debug(message, ...);
                        elseif level == "info" then
@@ -54,40 +48,23 @@ function make_logger(source_name, level)
 
        local source_handlers = name_sinks[source_name];
        
-       -- All your premature optimisation is belong to me!
-       local num_level_handlers, num_source_handlers = #level_handlers, source_handlers and #source_handlers;
-       
        local logger = function (message, ...)
                if source_handlers then
-                       for i = 1,num_source_handlers do
+                       for i = 1,#source_handlers do
                                if source_handlers[i](source_name, level, message, ...) == false then
                                        return;
                                end
                        end
                end
                
-               for i = 1,num_level_handlers do
+               for i = 1,#level_handlers do
                        level_handlers[i](source_name, level, message, ...);
                end
        end
 
-       -- To make sure our cached lengths stay in sync with reality
-       modify_hooks[logger] = function () num_level_handlers, num_source_handlers = #level_handlers, source_handlers and #source_handlers; end;
-       
        return logger;
 end
 
-function setwriter(f)
-       local old_func = outfunction;
-       if not f then outfunction = nil; return true, old_func; end
-       local ok, ret = pcall(f, "logger", "info", "Switched logging output successfully");
-       if ok then
-               outfunction = f;
-               ret = old_func;
-       end
-       return ok, ret;
-end
-
 function reset()
        for k in pairs(name_sinks) do name_sinks[k] = nil; end
        for level, handler_list in pairs(level_sinks) do
@@ -97,10 +74,6 @@ function reset()
                end
        end
        for k in pairs(name_patterns) do name_patterns[k] = nil; end
-
-       for _, modify_hook in pairs(modify_hooks) do
-               modify_hook();
-       end
 end
 
 function add_level_sink(level, sink_function)
@@ -109,10 +82,6 @@ function add_level_sink(level, sink_function)
        else
                level_sinks[level][#level_sinks[level] + 1 ] = sink_function;
        end
-       
-       for _, modify_hook in pairs(modify_hooks) do
-               modify_hook();
-       end
 end
 
 function add_name_sink(name, sink_function, exclusive)
@@ -121,10 +90,6 @@ function add_name_sink(name, sink_function, exclusive)
        else
                name_sinks[name][#name_sinks[name] + 1] = sink_function;
        end
-       
-       for _, modify_hook in pairs(modify_hooks) do
-               modify_hook();
-       end
 end
 
 function add_name_pattern_sink(name_pattern, sink_function, exclusive)