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, tags = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/hubbado/log/stderr_logger.rb', line 27

def log(subject, severity, message, data = nil, stacktrace = nil, tags = nil)
  return unless Display.shows?(severity, tags)

  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

#traces?(severity, tags = nil) ⇒ Boolean

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. Only a failure earns one on a terminal, and only if the operator is being shown it.

Returns:

  • (Boolean)


23
24
25
# File 'lib/hubbado/log/stderr_logger.rb', line 23

def traces?(severity, tags = nil)
  FAILURE_SEVERITIES.include?(severity.to_sym) && Display.shows?(severity, tags)
end