Class: SlackWebhookLogger::Formatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- SlackWebhookLogger::Formatter
- Defined in:
- lib/slack_webhook_logger/formatter.rb
Constant Summary collapse
- MAX_LENGTH =
3000
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#format ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/slack_webhook_logger/formatter.rb', line 15 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} #{SlackWebhookLogger.application_name} [#{ENV.fetch("RAILS_ENV", nil)}] (#{time})" text = " ```\n \#{msg2str(msg)}\n MSG\n\n slackify(truncate(title), \"\#{truncate(text)}```\")\n end\nend\n" |
Class Method Details
.fetch_text(hash) ⇒ Object
10 11 12 |
# File 'lib/slack_webhook_logger/formatter.rb', line 10 def fetch_text(hash) hash[:blocks].last[:text][:text] end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
43 44 45 |
# File 'lib/slack_webhook_logger/formatter.rb', line 43 def call(severity, time, progname, msg) format.call(severity, time, progname, msg) end |
#slackify(title, text) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/slack_webhook_logger/formatter.rb', line 47 def slackify(title, text) { blocks: [ { type: "section", text: { type: "mrkdwn", text: title, }, }, { type: "divider", }, { type: "section", text: { type: "mrkdwn", text: text, }, }, ], } end |