Class: Hubbado::Log::StderrLogger

Inherits:
LogHandler show all
Defined in:
lib/hubbado/log/stderr_logger.rb

Overview

Prints a log line where a person watching a run can see it.

Constant Summary collapse

FAILURE_SEVERITIES =

Where a stacktrace earns its space on a terminal. The logger synthesises one for warn too, but a warning is a condition to examine rather than a failure to trace, and its message already names the field and value — so a sweep that warns per row would bury itself in Ruby stack to solve a problem stderr does not have.

%i[error fatal unknown].freeze

Instance Method Summary collapse

Constructor Details

#initialize(io: nil) ⇒ StderrLogger

Returns a new instance of StderrLogger.



13
14
15
16
17
# File 'lib/hubbado/log/stderr_logger.rb', line 13

def initialize(io: nil)
  super()

  @io = io
end

Instance Method Details

#log(subject, severity, message, data = nil, stacktrace = nil) ⇒ Object

One write, because a line and the detail under it belong together. Three writes let a second thread put its own line between them, and a stacktrace filed under the wrong message is worse than no stacktrace.



22
23
24
25
26
27
28
# File 'lib/hubbado/log/stderr_logger.rb', line 22

def log(subject, severity, message, data = nil, stacktrace = nil)
  lines = ["#{severity.to_s.upcase} #{subject}: #{message}"]
  lines << detail(data, stacktrace) unless data.nil?
  lines << stacktrace if print_stacktrace?(severity, data, stacktrace)

  io.puts(lines.join("\n"))
end