diff options
| author | elijah <elijah@riseup.net> | 2013-01-30 22:05:05 -0800 | 
|---|---|---|
| committer | elijah <elijah@riseup.net> | 2013-01-30 22:05:05 -0800 | 
| commit | f688b404c7f1dbcd3650314d5b5279cf2a6657b7 (patch) | |
| tree | 000e217687000b6a9a57faaa4513405b2481bbe0 /lib | |
| parent | e13b80913f84a1d6154d7506d27d875e3b3cd239 (diff) | |
| download | leap_cli-f688b404c7f1dbcd3650314d5b5279cf2a6657b7.tar.gz leap_cli-f688b404c7f1dbcd3650314d5b5279cf2a6657b7.tar.bz2  | |
improve slightly the race conditions that can happen when logging from multiple threads.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/leap_cli/log.rb | 18 | 
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  | 
