Skip to content

Instantly share code, notes, and snippets.

@namtx
Created June 12, 2018 06:01
Show Gist options
  • Save namtx/e070c629ff9f0fad921f67c7de2b6769 to your computer and use it in GitHub Desktop.
Save namtx/e070c629ff9f0fad921f67c7de2b6769 to your computer and use it in GitHub Desktop.
How to use ActiveSupport::LogSubscriber
require 'active_support/log_subscriber'
module ActiveStorage
class LogSubscriber < ActiveSupport::LogSubscriber
def service_upload(event)
message = event.payload[:something]
info event, color(message, GREEN)
end
end
end
ActiveStorage::LogSubscriber.attach_to :active_storage
module ActiveStorage
class Service
def upload
instrument :upload, key: key, checksum: checksum
end
private
def instrument(operation, payload = {}, &block)
ActiveSupport::Notifications.instrument "service_#{operation}.active_storage", payload
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment