Class: Tango::Logger

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io = STDERR) ⇒ Logger

Returns a new instance of Logger.



23
24
25
26
# File 'lib/tango/logger.rb', line 23

def initialize(io = STDERR)
  @io = io
  @depth = 0
end

Class Method Details

.instanceObject



19
20
21
# File 'lib/tango/logger.rb', line 19

def self.instance
  @logger ||= Logger.new
end

Instance Method Details

#begin_step(step_name) ⇒ Object



28
29
30
31
# File 'lib/tango/logger.rb', line 28

def begin_step(step_name)
  log "#{yellow(step_name)} {"
  @depth += 1
end

#log(message, colour = nil) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/tango/logger.rb', line 43

def log(message, colour = nil)
  if colour && ::Tango::TermANSIColorStubs::ALLOWED_COLOURS.include?(colour)
    @io.puts send(colour,"#{indent}#{message}")

  else
    @io.puts "#{indent}#{message}"
  end
end

#log_raw(message) ⇒ Object



52
53
54
# File 'lib/tango/logger.rb', line 52

def log_raw(message)
  @io.write message
end

#step_met(step_name) ⇒ Object



33
34
35
36
# File 'lib/tango/logger.rb', line 33

def step_met(step_name)
  @depth -= 1
  log "} #{green("#{step_name}")}"
end

#step_not_met(step_name) ⇒ Object



38
39
40
41
# File 'lib/tango/logger.rb', line 38

def step_not_met(step_name)
  @depth -= 1
  log "} #{red("#{step_name}")}\n\n"
end