Sha256: 564d6d00f1c80857d273c2b8a0bc505af1e1b874ced59b5cd6a1df9784af0f0d
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
# frozen_string_literal: true module SlackWebhookLogger class Formatter < ::Logger::Formatter attr_writer :format 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})" text = <<~MSG #{msg2str(msg)} MSG slackify(title, text) end end def call(severity, time, progname, msg) format.call(severity, time, progname, msg) end 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 def msg2str(msg) case msg when ::String msg when ::Exception "#{msg.message} (#{msg.class})\n" << (msg.backtrace || []).join("\n") else msg.inspect end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
slack_webhook_logger-0.2.1 | lib/slack_webhook_logger/formatter.rb |
slack_webhook_logger-0.2.0 | lib/slack_webhook_logger/formatter.rb |