Created
June 12, 2018 06:01
-
-
Save namtx/e070c629ff9f0fad921f67c7de2b6769 to your computer and use it in GitHub Desktop.
How to use ActiveSupport::LogSubscriber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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