summaryrefslogtreecommitdiff
path: root/lib/leap_cli
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-01-30 22:05:05 -0800
committerelijah <elijah@riseup.net>2013-01-30 22:05:05 -0800
commitf688b404c7f1dbcd3650314d5b5279cf2a6657b7 (patch)
tree000e217687000b6a9a57faaa4513405b2481bbe0 /lib/leap_cli
parente13b80913f84a1d6154d7506d27d875e3b3cd239 (diff)
improve slightly the race conditions that can happen when logging from multiple threads.
Diffstat (limited to 'lib/leap_cli')
-rw-r--r--lib/leap_cli/log.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/leap_cli/log.rb b/lib/leap_cli/log.rb
index 89cf0ba..0bc48a1 100644
--- a/lib/leap_cli/log.rb
+++ b/lib/leap_cli/log.rb
@@ -3,6 +3,8 @@ require 'paint'
##
## LOGGING
##
+## Ugh. This class does not work well with multiple threads!
+##
module LeapCli
extend self
@@ -51,11 +53,12 @@ module LeapCli
options = args.grep(Hash).first || {}
options[:indent] ||= LeapCli.indent_level
if message && LeapCli.log_level >= level
- print " " * (options[:indent])
+ line = ""
+ line += " " * (options[:indent])
if options[:indent] > 0
- print ' - '
+ line += ' - '
else
- print ' = '
+ line += ' = '
end
if title
prefix = case title
@@ -78,17 +81,18 @@ module LeapCli
else [title.to_s, :cyan, :bold]
end
if options[:host]
- print "[%s] %s " % [Paint[options[:host], prefix[1], prefix[2]], prefix[0]]
+ line += "[%s] %s " % [Paint[options[:host], prefix[1], prefix[2]], prefix[0]]
else
- print "%s " % Paint[prefix[0], prefix[1], prefix[2]]
+ line += "%s " % Paint[prefix[0], prefix[1], prefix[2]]
end
if FILE_TITLES.include?(title) && message =~ /^\//
message = LeapCli::Path.relative_path(message)
end
elsif options[:host]
- print "[%s] " % options[:host]
+ line += "[%s] " % options[:host]
end
- puts "#{message}"
+ line += "#{message}\n"
+ print line
if block_given?
LeapCli.indent_level += 1
yield