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
19
20
21
# File 'lib/runtime_command/logger.rb', line 10

def initialize(output = true, colors = {})
  @output = output
  @has_color = colors != :none

  if @has_color
    @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)
  end

  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



65
66
67
68
69
70
71
# File 'lib/runtime_command/logger.rb', line 65

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

  nil
end

#stderr(line) ⇒ Object

Parameters:

  • line (String)


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

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

  @buffered_log << line
  @buffered_stderr << line

  nil
end

#stderr?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/runtime_command/logger.rb', line 50

def stderr?
  !@buffered_stderr.empty?
end

#stdin(line) ⇒ Object

Parameters:

  • line (String)


24
25
26
27
28
29
30
31
# File 'lib/runtime_command/logger.rb', line 24

def stdin(line)
  puts HighLine.color(line, @stdin_color) if @output && @has_color
  puts line if @output && !@has_color

  @buffered_log << line + "\n"

  nil
end

#stdout(line) ⇒ Object

Parameters:

  • line (String)


39
40
41
42
43
44
45
46
47
# File 'lib/runtime_command/logger.rb', line 39

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

  @buffered_log << line
  @buffered_stdout << line

  nil
end

#stdout?Boolean

Returns:

  • (Boolean)


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

def stdout?
  !@buffered_stdout.empty?
end