class SlackWebhookLogger::Formatter
Attributes
format[W]
Public Instance Methods
call(severity, time, progname, msg)
click to toggle source
# File lib/slack_webhook_logger/formatter.rb, line 34 def call(severity, time, progname, msg) format.call(severity, time, progname, msg) end
format()
click to toggle source
# File lib/slack_webhook_logger/formatter.rb, line 7 def format @format ||= proc do |severity, time, _progname, msg| heading = case severity when 'FATAL' "đ *#{severity}*" when 'ERROR' "đ *#{severity}*" when 'WARN' "â ī¸ *#{severity}*" when 'INFO' "âšī¸ *#{severity}*" when 'DEBUG' "đ *#{severity}*" else 'đĒĩ *Logger*' end title = "#{heading} (#{time}) [#{ENV['RAILS_ENV']}]" text = <<~MSG #{msg2str(msg)} MSG slackify(title, text) end end
slackify(title, text)
click to toggle source
# File lib/slack_webhook_logger/formatter.rb, line 38 def slackify(title, text) { text: [title, text].join("\n").to_s, blocks: [ { type: 'section', text: { type: 'mrkdwn', text: title } }, { type: 'divider' }, { type: 'section', text: { type: 'plain_text', text: text } } ] } end
Private Instance Methods
msg2str(msg)
click to toggle source
# File lib/slack_webhook_logger/formatter.rb, line 63 def msg2str(msg) case msg when ::String msg when ::Exception "#{msg.message} (#{msg.class})\n" << (msg.backtrace || []).join("\n") else msg.inspect end end