class MotherBrain::Logging::BasicFormat

Public Instance Methods

call(severity, datetime, progname, msg) click to toggle source
# File lib/mb/logging/basic_format.rb, line 4
def call(severity, datetime, progname, msg)
  message = msg.to_s

  if match = message.match(/NODE\[.+?\]/)
    format_matched_lines match, message
  else
    "[#{datetime.utc.iso8601}] PID[#{Process.pid}] TID[#{Thread.current.object_id.to_s(36)}] #{severity}: #{message}\n"
  end
end

Private Instance Methods

format_matched_lines(match, message) click to toggle source
# File lib/mb/logging/basic_format.rb, line 16
def format_matched_lines(match, message)
  lines = message.lines.to_a

  lines.map! do |line|
    if line.start_with? match.to_s
      line
    else
      "#{match} #{line}"
    end
  end

  lines.join("\n") << "\n"
end