class UU::LoggerStderr::Formatter

Constants

PATHS

Attributes

context[R]

Public Class Methods

new(context) click to toggle source
# File lib/uu/logger_stderr.rb, line 10
def initialize(context)
  @context = context
end

Public Instance Methods

call(severity, time, _progname, msg) click to toggle source
# File lib/uu/logger_stderr.rb, line 16
def call(severity, time, _progname, msg)
  loc = meaningful_location
  short_severity = severity[0, 1]
  time_format = time.utc.strftime('%T')
  context = @context.context
  context_msg = context.empty? ? '' : "#{context.to_json} "

  "#{short_severity}]#{time_format}" \
    "[#{loc[:filename]}##{loc[:method]}:#{loc[:lineno]}] " \
    "#{context_msg}" \
    "#{msg}\n"
end
find_location() click to toggle source
# File lib/uu/logger_stderr.rb, line 45
def find_location
  caller_locations.find do |location_|
    location_.path != __FILE__ &&
      PATHS.none? { |path| location_.path.end_with?(path) }
  end
end
meaningful_location() click to toggle source
# File lib/uu/logger_stderr.rb, line 29
def meaningful_location
  location = find_location
  {
    filename: File.basename(location.path),
    method: location.label,
    lineno: location.lineno,
  }
end