Class: RuntimeCommand::Logger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output = true, colors = {}) ⇒ Object

Returns RuntimeCommand::Logger.

Parameters:

  • output (Boolean) (defaults to: true)
  • colors (Hash) (defaults to: {})


10
11
12
13
14
15
16
17
18
# File 'lib/runtime_command/logger.rb', line 10

def initialize(output = true, colors = {})
  @output = output

  @stdin_color = colors[:stdin] || HighLine::Style.rgb(204, 204, 0)
  @stdout_color = colors[:stdout] || HighLine::Style.rgb(64, 64, 64)
  @stderr_color = colors[:stderr] || HighLine::Style.rgb(255, 51, 51)

  flash
end

Instance Attribute Details

#buffered_logObject (readonly)

Returns the value of attribute buffered_log.



5
6
7
# File 'lib/runtime_command/logger.rb', line 5

def buffered_log
  @buffered_log
end

#buffered_stderrObject (readonly)

Returns the value of attribute buffered_stderr.



5
6
7
# File 'lib/runtime_command/logger.rb', line 5

def buffered_stderr
  @buffered_stderr
end

#buffered_stdoutObject (readonly)

Returns the value of attribute buffered_stdout.



5
6
7
# File 'lib/runtime_command/logger.rb', line 5

def buffered_stdout
  @buffered_stdout
end

Instance Method Details

#flashObject



58
59
60
61
62
63
64
# File 'lib/runtime_command/logger.rb', line 58

def flash
  @buffered_log = ''
  @buffered_stdout = ''
  @buffered_stderr = ''

  return
end

#stderr(line) ⇒ Object

Parameters:

  • line (String)


49
50
51
52
53
54
55
56
# File 'lib/runtime_command/logger.rb', line 49

def stderr(line)
  puts HighLine.color(line.chomp, @stderr_color) if @output

  @buffered_log << line
  @buffered_stderr << line

  return
end

#stderr?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/runtime_command/logger.rb', line 44

def stderr?
  !@buffered_stderr.empty?
end

#stdin(line) ⇒ Object

Parameters:

  • line (String)


21
22
23
24
25
26
# File 'lib/runtime_command/logger.rb', line 21

def stdin(line)
  puts HighLine.color(line, @stdin_color) if @output
  @buffered_log << line + "\n"

  return
end

#stdout(line) ⇒ Object

Parameters:

  • line (String)


34
35
36
37
38
39
40
41
# File 'lib/runtime_command/logger.rb', line 34

def stdout(line)
  puts HighLine.color(line.chomp, @stdout_color) if @output

  @buffered_log << line
  @buffered_stdout << line

  return
end

#stdout?Boolean

Returns:

  • (Boolean)


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

def stdout?
  !@buffered_stdout.empty?
end