From 0bedf44f159121c7ee58d937a3fd3bb43684bce1 Mon Sep 17 00:00:00 2001 From: Laurent Sansonetti Date: Tue, 3 Jan 2012 11:21:17 +0100 Subject: [PATCH] make sure log output isn't messed when performing concurrent tasks --- lib/motion/project/app.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/motion/project/app.rb b/lib/motion/project/app.rb index 6f6fac35..bf746535 100644 --- a/lib/motion/project/app.rb +++ b/lib/motion/project/app.rb @@ -35,8 +35,12 @@ module Motion; module Project end def log(what, msg) - what = "\e[1m" + what.rjust(10) + "\e[0m" # bold - $stderr.puts what + ' ' + msg + @print_mutex ||= Mutex.new + # Because this method can be called concurrently, we don't want to mess any output. + @print_mutex.synchronize do + what = "\e[1m" + what.rjust(10) + "\e[0m" # bold + $stderr.puts what + ' ' + msg + end end def warn(msg)