Class: EmojiLog::ActionController
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- EmojiLog::ActionController
- Defined in:
- lib/emoji_log.rb
Constant Summary collapse
- ONE =
100...199
- TWO =
200...299
- THREE =
300...399
- FOUR =
400...499
- FIVE =
500...599
Instance Method Summary collapse
Instance Method Details
#emoji_speed(event) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/emoji_log.rb', line 78 def emoji_speed(event) if event.duration <= EmojiLog.fast_threshold EmojiLog.fast elsif event.duration <= EmojiLog.average_threshold EmojiLog.average else EmojiLog.slow end end |
#emoji_status(status) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/emoji_log.rb', line 59 def emoji_status(status) case status when ONE " #{EmojiLog.info}" when TWO " #{EmojiLog.success}" when THREE " #{EmojiLog.redirect}" when FOUR " #{EmojiLog.bad}" when FIVE " #{EmojiLog.error}" when 0 " #{EmojiLog.cancelled}" else "" end end |
#process_action(event) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/emoji_log.rb', line 36 def process_action(event) info do payload = event.payload additions = ::ActionController::Base.log_process_action(payload) status = payload[:status] if status.nil? && (exception_class_name = payload[:exception]&.first) status = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name) end additions << "Allocations: #{event.allocations}" speed_emoji = emoji_speed(event) status_emoji = emoji_status(status) = +"#{speed_emoji * 3} [#{payload[:path]}] Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}#{status_emoji} in #{event.duration.round}ms" \ " (#{additions.join(" | ")})" << "\n\n" if defined?(::Rails.env) && ::Rails.env.development? end end |