Class: Daedalus::Logger
- Inherits:
-
Object
- Object
- Daedalus::Logger
- Defined in:
- lib/daedalus.rb
Direct Known Subclasses
Instance Method Summary collapse
- #command(cmd) ⇒ Object
- #inc! ⇒ Object
- #info(str) ⇒ Object
-
#initialize(level = 3) ⇒ Logger
constructor
A new instance of Logger.
- #show(kind, cmd) ⇒ Object
- #start(count) ⇒ Object
- #stop ⇒ Object
- #thread_id ⇒ Object
- #verbose(str) ⇒ Object
Constructor Details
#initialize(level = 3) ⇒ Logger
Returns a new instance of Logger.
22 23 24 25 26 27 28 29 |
# File 'lib/daedalus.rb', line 22 def initialize(level=3) @count = 0 @total = nil @level = level @thread_count = 0 @count_mutex = Mutex.new end |
Instance Method Details
#command(cmd) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/daedalus.rb', line 64 def command(cmd) system cmd if $?.exitstatus != 0 STDOUT.puts "Error: #{cmd}" raise "Error compiling" end end |
#inc! ⇒ Object
52 53 54 |
# File 'lib/daedalus.rb', line 52 def inc! @count += 1 end |
#info(str) ⇒ Object
78 79 80 81 82 |
# File 'lib/daedalus.rb', line 78 def info(str) if @level >= 3 STDOUT.puts "daedalus: #{str}" end end |
#show(kind, cmd) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/daedalus.rb', line 56 def show(kind, cmd) if @total STDOUT.puts "[%3d/%3d] #{kind} #{cmd}" % [@count, @total] else STDOUT.puts "#{thread_id}: #{kind} #{cmd}" end end |
#start(count) ⇒ Object
43 44 45 46 |
# File 'lib/daedalus.rb', line 43 def start(count) @count = 0 @total = count end |
#stop ⇒ Object
48 49 50 |
# File 'lib/daedalus.rb', line 48 def stop @total = nil end |
#thread_id ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/daedalus.rb', line 31 def thread_id id = Thread.current[:build_id] unless id @count_mutex.synchronize do @thread_count += 1 id = Thread.current[:build_id] = @thread_count end end return id end |
#verbose(str) ⇒ Object
72 73 74 75 76 |
# File 'lib/daedalus.rb', line 72 def verbose(str) if @level >= 5 STDOUT.puts "daedalus: #{str}" end end |