Skip to content

Commit

Permalink
Merge pull request #46291 from chaadow/preview-log-subscriber
Browse files Browse the repository at this point in the history
Add missing `preview` event  to `ActiveStorage::LogSubscriber`
  • Loading branch information
byroot committed Oct 22, 2022
2 parents 7fdcbe7 + 0b8496f commit e067745
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions activestorage/CHANGELOG.md
@@ -1,3 +1,14 @@
* Add missing preview event to `ActiveStorage::LogSubscriber`

A `preview` event is being instrumented in `ActiveStorage::Previewer`.
However it was not added inside ActiveStorage's LogSubscriber class.

This will allow to have logs for when a preview happens
in the same fashion as all other ActiveStorage events such as
`upload` and `download` inside `Rails.logger`.

*Chedli Bourguiba*

* Fix retrieving rotation value from FFmpeg on version 5.0+.

In FFmpeg version 5.0+ the rotation value has been removed from tags.
Expand Down
5 changes: 5 additions & 0 deletions activestorage/lib/active_storage/log_subscriber.rb
Expand Up @@ -18,6 +18,11 @@ def service_download(event)

alias_method :service_streaming_download, :service_download

def preview(event)
info event, color("Previewed file from key: #{key_in(event)}", BLUE)
end
subscribe_log_level :preview, :info

def service_delete(event)
info event, color("Deleted file from key: #{key_in(event)}", RED)
end
Expand Down
7 changes: 6 additions & 1 deletion activestorage/lib/active_storage/previewer.rb
Expand Up @@ -65,7 +65,12 @@ def open_tempfile
end

def instrument(operation, payload = {}, &block)
ActiveSupport::Notifications.instrument "#{operation}.active_storage", payload, &block
ActiveSupport::Notifications.instrument "#{operation}.active_storage", payload.merge(service: service_name), &block
end

def service_name
# ActiveStorage::Service::DiskService => Disk
blob.service.class.to_s.split("::").third.remove("Service")
end

def capture(*argv, to:)
Expand Down

0 comments on commit e067745

Please sign in to comment.