Class: Daedalus::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/daedalus.rb

Direct Known Subclasses

FancyLogger

Instance Method Summary collapse

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

#stopObject



48
49
50
# File 'lib/daedalus.rb', line 48

def stop
  @total = nil
end

#thread_idObject



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