util.cache: Add support for creating a proxy table to a cache, that looks and acts...
[prosody.git] / core / loggingmanager.lua
index 003982294163b0623482ae4b9faddad0f0753923..e3a83817b5d239c2009bc0261b674ad71ef98b7b 100644 (file)
@@ -15,13 +15,9 @@ local io_open = io.open;
 local math_max, rep = math.max, string.rep;
 local os_date = os.date;
 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
-
--- COMPAT: This should no longer be needed since the addition of setvbuf calls
-if os.getenv("__FLUSH_LOG") then
-       local io_flush = io.flush;
-       local _io_write = io_write;
-       io_write = function(...) _io_write(...); io_flush(); end
-end
+local tostring = tostring;
+local select = select;
+local unpack = table.unpack or unpack; --luacheck: ignore 113
 
 local config = require "core.configmanager";
 local logger = require "util.logger";
@@ -199,17 +195,22 @@ local function log_to_file(sink_config, logfile)
        local sourcewidth = sink_config.source_width;
 
        return function (name, level, message, ...)
+               local n = select('#', ...);
+               if n ~= 0 then
+                       local arg = { ... };
+                       for i = 1, n do
+                               arg[i] = tostring(arg[i]);
+                       end
+                       message = format(message, unpack(arg, 1, n));
+               end
+
                if sourcewidth then
                        sourcewidth = math_max(#name+2, sourcewidth);
                        name = name ..  rep(" ", sourcewidth-#name);
                else
                        name = name .. "\t";
                end
-               if ... then
-                       write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", format(message, ...), "\n");
-               else
-                       write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", message, "\n");
-               end
+               write(logfile, timestamps and os_date(timestamps) or "", name, level, "\t", message, "\n");
        end
 end
 log_sink_types.file = log_to_file;