Makefile: Set data directory permissions to 750 on install [thanks Dwayne Bent]
[prosody.git] / core / loggingmanager.lua
index 13b091cce6c94c361bdb0d427d92797c30c4e61e..aa8f368d73e2fe962074974ba6378191b02d1531 100644 (file)
@@ -10,7 +10,7 @@ local os_date, os_getenv = os.date, os.getenv;
 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
 
 local config = require "core.configmanager";
-
+local eventmanager = require "core.eventmanager";
 local logger = require "util.logger";
 
 _G.log = logger.init("general");
@@ -86,6 +86,9 @@ function apply_sink_rules(sink_type)
                        add_rule(sink_config);
                        sink_config.filename = nil;
                end
+       elseif type(logging_config) == "string" and logging_config:match("^%*(.+)") == sink_type then
+               -- Log all levels (debug+) to this sink
+               add_rule({ levels = { min = "debug" }, to = sink_type });
        end
 end
 
@@ -122,6 +125,7 @@ end
 
 --- Definition of built-in logging sinks ---
 
+-- Null sink, must enter log_sink_types *first*
 function log_sink_types.nowhere()
        return function () return false; end;
 end
@@ -186,12 +190,26 @@ do
        end
 end
 
+local empty_function = function () end;
 function log_sink_types.file(config)
        local log = config.filename;
        local logfile = io_open(log, "a+");
        if not logfile then
-               return function () end
+               return empty_function;
        end
+       local write, flush = logfile.write, logfile.flush;
+
+       eventmanager.add_event_hook("reopen-log-files", function ()
+                       if logfile then
+                               logfile:close();
+                       end
+                       logfile = io_open(log, "a+");
+                       if not logfile then
+                               write, flush = empty_function, empty_function;
+                       else
+                               write, flush = logfile.write, logfile.flush;
+                       end
+               end);
 
        local timestamps = config.timestamps;
 
@@ -199,7 +217,6 @@ function log_sink_types.file(config)
                timestamps = default_timestamp; -- Default format
        end
 
-       local write, format, flush = logfile.write, format, logfile.flush;
        return function (name, level, message, ...)
                if timestamps then
                        write(logfile, os_date(timestamps), " ");