loggingmanager: File log sinks react to reopen-log-files event

Tue, 05 May 2009 14:19:20 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 05 May 2009 14:19:20 +0100
changeset 1117
360ec48ea780
parent 1116
507702cf44f8
child 1118
239d4362a040

loggingmanager: File log sinks react to reopen-log-files event

core/loggingmanager.lua file | annotate | diff | comparison | revisions
--- a/core/loggingmanager.lua	Tue May 05 14:17:06 2009 +0100
+++ b/core/loggingmanager.lua	Tue May 05 14:19:20 2009 +0100
@@ -10,7 +10,7 @@
 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");
@@ -190,12 +190,26 @@
 	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;
 
@@ -203,7 +217,6 @@
 		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), " ");

mercurial