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 = nil) ⇒ Logger

Returns a new instance of Logger.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/runtime_command/logger.rb', line 5

def initialize(output = true, colors = nil)
  @output = output

  stdin_rgb = [204, 204, 0]
  stdout_rgb = [64, 64, 64]
  stderr_rgb = [255, 51, 51]

  if colors
    stdin_rgb = colors[:stdin] if colors.has_key?(:stdin)
    stdout_rgb = colors[:stdout] if colors.has_key?(:stdout)
    stderr_rgb = colors[:stderr] if colors.has_key?(:stderr)
  end

  @stdin_color = HighLine::Style.rgb(*stdin_rgb)
  @stdout_color = HighLine::Style.rgb(*stdout_rgb)
  @stderr_color = HighLine::Style.rgb(*stderr_rgb)

  flash
end

Instance Attribute Details

#buffered_logObject (readonly)

Returns the value of attribute buffered_log.



3
4
5
# File 'lib/runtime_command/logger.rb', line 3

def buffered_log
  @buffered_log
end

#buffered_stderrObject (readonly)

Returns the value of attribute buffered_stderr.



3
4
5
# File 'lib/runtime_command/logger.rb', line 3

def buffered_stderr
  @buffered_stderr
end

#buffered_stdoutObject (readonly)

Returns the value of attribute buffered_stdout.



3
4
5
# File 'lib/runtime_command/logger.rb', line 3

def buffered_stdout
  @buffered_stdout
end

Instance Method Details

#flashObject



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

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

  return
end

#stderr(line) ⇒ Object



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

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

  @buffered_log << line
  @buffered_stderr << line

  return
end

#stdin(line) ⇒ Object



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

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

  return
end

#stdout(line) ⇒ Object



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

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

  @buffered_log << line
  @buffered_stdout << line

  return
end