Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing f…
…rameworks like ActiveRecord and ActiveResource to log outsude Rails::Application [#4816 state:resolved]
- Loading branch information
Showing
34 changed files
with
266 additions
and
317 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'active_support/core_ext/array/wrap' | ||
|
||
module ActionMailer | ||
class LogSubscriber < ActiveSupport::LogSubscriber | ||
def deliver(event) | ||
recipients = Array.wrap(event.payload[:to]).join(', ') | ||
info("\nSent mail to #{recipients} (%1.fms)" % event.duration) | ||
debug(event.payload[:mail]) | ||
end | ||
|
||
def receive(event) | ||
info("\nReceived mail (%.1fms)" % event.duration) | ||
debug(event.payload[:mail]) | ||
end | ||
|
||
def logger | ||
ActionMailer::Base.logger | ||
end | ||
end | ||
end | ||
|
||
ActionMailer::LogSubscriber.attach_to :action_mailer |
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require "action_controller/log_subscriber" | ||
|
||
module ActionController | ||
class Base < Metal | ||
abstract! | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'active_support/core_ext/object/blank' | ||
|
||
module ActionController | ||
class LogSubscriber < ActiveSupport::LogSubscriber | ||
INTERNAL_PARAMS = %w(controller action format _method only_path) | ||
|
||
def start_processing(event) | ||
payload = event.payload | ||
params = payload[:params].except(*INTERNAL_PARAMS) | ||
|
||
info " Processing by #{payload[:controller]}##{payload[:action]} as #{payload[:formats].first.to_s.upcase}" | ||
info " Parameters: #{params.inspect}" unless params.empty? | ||
end | ||
|
||
def process_action(event) | ||
payload = event.payload | ||
additions = ActionController::Base.log_process_action(payload) | ||
|
||
message = "Completed #{payload[:status]} #{Rack::Utils::HTTP_STATUS_CODES[payload[:status]]} in %.0fms" % event.duration | ||
message << " (#{additions.join(" | ")})" unless additions.blank? | ||
|
||
info(message) | ||
end | ||
|
||
def send_file(event) | ||
message = "Sent file %s" | ||
message << " (%.1fms)" | ||
info(message % [event.payload[:path], event.duration]) | ||
end | ||
|
||
def redirect_to(event) | ||
info "Redirected to #{event.payload[:location]}" | ||
end | ||
|
||
def send_data(event) | ||
info("Sent data %s (%.1fms)" % [event.payload[:filename], event.duration]) | ||
end | ||
|
||
%w(write_fragment read_fragment exist_fragment? | ||
expire_fragment expire_page write_page).each do |method| | ||
class_eval <<-METHOD, __FILE__, __LINE__ + 1 | ||
def #{method}(event) | ||
key_or_path = event.payload[:key] || event.payload[:path] | ||
human_name = #{method.to_s.humanize.inspect} | ||
info("\#{human_name} \#{key_or_path} (%.1fms)" % event.duration) | ||
end | ||
METHOD | ||
end | ||
|
||
def logger | ||
ActionController::Base.logger | ||
end | ||
end | ||
end | ||
|
||
ActionController::LogSubscriber.attach_to :action_controller |
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
56 changes: 0 additions & 56 deletions
56
actionpack/lib/action_controller/railties/log_subscriber.rb
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module ActionView | ||
# = Action View Log Subscriber | ||
# | ||
# Provides functionality so that Rails can output logs from Action View. | ||
class LogSubscriber < ActiveSupport::LogSubscriber | ||
def render_template(event) | ||
message = "Rendered #{from_rails_root(event.payload[:identifier])}" | ||
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout] | ||
message << (" (%.1fms)" % event.duration) | ||
info(message) | ||
end | ||
alias :render_partial :render_template | ||
alias :render_collection :render_template | ||
|
||
def logger | ||
ActionController::Base.logger | ||
end | ||
|
||
protected | ||
|
||
def from_rails_root(string) | ||
string.sub("#{Rails.root}/", "").sub(/^app\/views\//, "") | ||
end | ||
end | ||
end | ||
|
||
ActionView::LogSubscriber.attach_to :action_view |
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
This file was deleted.
Oops, something went wrong.
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
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
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
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
Oops, something went wrong.
6788db8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very glad to see this change!