Class: Cheetah::DefaultRecorder

Inherits:
Recorder
  • Object
show all
Defined in:
lib/cheetah.rb

Overview

A default recorder. It uses the ‘Logger::INFO` level for normal messages and the `Logger::ERROR` level for messages about errors (non-zero exit status or non-empty error output). Used by run when a logger is passed.

Constant Summary collapse

STREAM_INFO =
{
  stdin: { name: "Standard input", method: :info },
  stdout: { name: "Standard output", method: :info  },
  stderr: { name: "Error output",    method: :error }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ DefaultRecorder

Returns a new instance of DefaultRecorder.



153
154
155
156
157
158
159
160
# File 'lib/cheetah.rb', line 153

def initialize(logger)
  super()

  @logger = logger

  @stream_used   = { stdin: false, stdout: false, stderr: false }
  @stream_buffer = { stdin: +"", stdout: +"", stderr: +"" }
end

Instance Method Details

#record_commands(commands) ⇒ Object



162
163
164
# File 'lib/cheetah.rb', line 162

def record_commands(commands)
  @logger.info "Executing #{format_commands(commands)}."
end

#record_status(status, allowed_status) ⇒ Object



178
179
180
181
182
183
184
185
# File 'lib/cheetah.rb', line 178

def record_status(status, allowed_status)
  log_stream_remainder(:stdin)
  log_stream_remainder(:stdout)
  log_stream_remainder(:stderr)

  @logger.send allowed_status ? :info : :error,
               "Status: #{status.exitstatus}"
end

#record_stderr(stderr) ⇒ Object



174
175
176
# File 'lib/cheetah.rb', line 174

def record_stderr(stderr)
  log_stream_increment(:stderr, stderr)
end

#record_stdin(stdin) ⇒ Object



166
167
168
# File 'lib/cheetah.rb', line 166

def record_stdin(stdin)
  log_stream_increment(:stdin, stdin)
end

#record_stdout(stdout) ⇒ Object



170
171
172
# File 'lib/cheetah.rb', line 170

def record_stdout(stdout)
  log_stream_increment(:stdout, stdout)
end