Diff

util/logger.lua @ 3357:1dd83dd2b832

util.logger: Add reset() method to clear all sinks
author Matthew Wild <mwild1@gmail.com>
date Wed, 14 Jul 2010 01:23:14 +0100
parent 2923:b7049746bd29
child 3455:67cdc0366d46
line wrap: on
line diff
--- a/util/logger.lua	Tue Jul 13 15:28:52 2010 +0100
+++ b/util/logger.lua	Wed Jul 14 01:23:14 2010 +0100
@@ -103,6 +103,21 @@
 	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
+		-- Clear all handlers for this level
+		for i = 1, #handler_list do
+			handler_list[i] = nil;
+		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)
 	if not level_sinks[level] then
 		level_sinks[level] = { sink_function };