Class: RuntimeCommand::Logger
- Inherits:
-
Object
- Object
- RuntimeCommand::Logger
- Defined in:
- lib/runtime_command/logger.rb
Instance Attribute Summary collapse
-
#buffered_log ⇒ Object
readonly
Returns the value of attribute buffered_log.
-
#buffered_stderr ⇒ Object
readonly
Returns the value of attribute buffered_stderr.
-
#buffered_stdout ⇒ Object
readonly
Returns the value of attribute buffered_stdout.
Instance Method Summary collapse
- #flash ⇒ Object
-
#initialize(options = {}) ⇒ Object
constructor
RuntimeCommand::Logger.
- #stderr(line) ⇒ Object
- #stderr? ⇒ Boolean
- #stdin(line) ⇒ Object
- #stdout(line) ⇒ Object
- #stdout? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Object
Returns RuntimeCommand::Logger.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/runtime_command/logger.rb', line 11 def initialize( = {}) @options = @has_color = [:colors] != :none if @has_color @stdin_color = .dig(:colors, :stdin) || HighLine::Style.rgb(204, 204, 0) @stdout_color = .dig(:colors, :stdout) || HighLine::Style.rgb(64, 64, 64) @stderr_color = .dig(:colors, :stderr) || HighLine::Style.rgb(255, 51, 51) end flash end |
Instance Attribute Details
#buffered_log ⇒ Object (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_stderr ⇒ Object (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_stdout ⇒ Object (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
#flash ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/runtime_command/logger.rb', line 68 def flash @buffered_log = '' @buffered_stdout = '' @buffered_stderr = '' nil end |
#stderr(line) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/runtime_command/logger.rb', line 57 def stderr(line) trim_line = line.chomp puts @has_color ? HighLine.color(trim_line, @stderr_color) : line if @options[:output] @options[:logger].error(trim_line) if @options[:logger] @buffered_log << line @buffered_stderr << line nil end |
#stderr? ⇒ Boolean
52 53 54 |
# File 'lib/runtime_command/logger.rb', line 52 def stderr? !@buffered_stderr.empty? end |
#stdin(line) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/runtime_command/logger.rb', line 25 def stdin(line) puts @has_color ? HighLine.color(line, @stdin_color) : line if @options[:output] @options[:logger].info(line) if @options[:logger] @buffered_log << line + "\n" nil end |
#stdout(line) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/runtime_command/logger.rb', line 40 def stdout(line) trim_line = line.chomp puts @has_color ? HighLine.color(trim_line, @stdout_color) : line if @options[:output] @options[:logger].info(trim_line) if @options[:logger] @buffered_log << line @buffered_stdout << line nil end |
#stdout? ⇒ Boolean
35 36 37 |
# File 'lib/runtime_command/logger.rb', line 35 def stdout? !@buffered_stdout.empty? end |