# HG changeset patch
# User Matthew Wild <mwild1@gmail.com>
# Date 1454597865 0
# Node ID de3659191e900a26b0f70f52075ab4ff8a3fda7a
# Parent  a0764a8d6b2610999baeebc088dcdac39bf98a0e# Parent  631c47a655197de972885a22cce75321cced2baa
Merge 0.10->trunk

diff -r a0764a8d6b26 -r de3659191e90 core/loggingmanager.lua
--- a/core/loggingmanager.lua	Thu Feb 04 09:18:53 2016 +0100
+++ b/core/loggingmanager.lua	Thu Feb 04 14:57:45 2016 +0000
@@ -15,6 +15,7 @@
 local os_date = os.date;
 local getstyle, setstyle = require "util.termcolours".getstyle, require "util.termcolours".setstyle;
 
+-- 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;
@@ -157,7 +158,6 @@
 
 	logging_config = config.get("*", "log") or default_logging;
 
-
 	for name, sink_maker in pairs(old_sink_types) do
 		log_sink_types[name] = sink_maker;
 	end
@@ -185,6 +185,10 @@
 		timestamps = default_timestamp; -- Default format
 	end
 
+	if sink_config.buffer_mode ~= false then
+		io.stdout:setvbuf(sink_config.buffer_mode or "line");
+	end
+
 	return function (name, level, message, ...)
 		sourcewidth = math_max(#name+2, sourcewidth);
 		local namelen = #name;
@@ -220,6 +224,10 @@
 			timestamps = default_timestamp; -- Default format
 		end
 
+		if sink_config.buffer_mode ~= false then
+			io.stdout:setvbuf(sink_config.buffer_mode or "line");
+		end
+
 		return function (name, level, message, ...)
 			sourcewidth = math_max(#name+2, sourcewidth);
 			local namelen = #name;
@@ -247,7 +255,12 @@
 	if not logfile then
 		return empty_function;
 	end
-	local write, flush = logfile.write, logfile.flush;
+
+	if sink_config.buffer_mode ~= false then
+		logfile:setvbuf(sink_config.buffer_mode or "line");
+	end
+
+	local write = logfile.write;
 
 	local timestamps = sink_config.timestamps;
 
@@ -264,7 +277,6 @@
 		else
 			write(logfile, name, "\t" , level, "\t", message, "\n");
 		end
-		flush(logfile);
 	end;
 end