Monkeypatching to change rails default logging to something more useful
This commit is contained in:
parent
037f822287
commit
1fb58c53fb
2 changed files with 33 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ require 'active_resource/railtie'
|
||||||
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
||||||
|
|
||||||
require File.expand_path('../../lib/mongo_mapper/bson_id', __FILE__)
|
require File.expand_path('../../lib/mongo_mapper/bson_id', __FILE__)
|
||||||
|
require File.expand_path('../../lib/log_overrider', __FILE__)
|
||||||
module Diaspora
|
module Diaspora
|
||||||
class Application < Rails::Application
|
class Application < Rails::Application
|
||||||
# Settings in config/environments/* take precedence over those specified here.
|
# Settings in config/environments/* take precedence over those specified here.
|
||||||
|
|
|
||||||
32
lib/log_overrider.rb
Normal file
32
lib/log_overrider.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
class ActionView::LogSubscriber
|
||||||
|
def render_template(event)
|
||||||
|
message = "event=render "
|
||||||
|
message << "template=#{from_rails_root(event.payload[:identifier])} "
|
||||||
|
message << "layout=#{from_rails_root(event.payload[:layout])} " if event.payload[:layout]
|
||||||
|
message << "time=#{("%.1fms" % event.duration)}"
|
||||||
|
info(message)
|
||||||
|
end
|
||||||
|
alias :render_partial :render_template
|
||||||
|
alias :render_collection :render_template
|
||||||
|
end
|
||||||
|
|
||||||
|
class ActionController::LogSubscriber
|
||||||
|
def start_processing(event)
|
||||||
|
payload = event.payload
|
||||||
|
params = payload[:params].except(*INTERNAL_PARAMS)
|
||||||
|
log_string = "event=request_routed controller=#{payload[:controller]} action=#{payload[:action]} format=#{payload[:formats].first.to_s.upcase} "
|
||||||
|
log_string << "params='#{params.inspect}'" unless params.empty?
|
||||||
|
info(log_string)
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_action(event)
|
||||||
|
payload = event.payload
|
||||||
|
additions = ActionController::Base.log_process_action(payload)
|
||||||
|
|
||||||
|
log_string = "event=request_completed status=#{payload[:status]} "
|
||||||
|
log_string << "hstatus=#{Rack::Utils::HTTP_STATUS_CODES[payload[:status]]} time=#{"%.0fms" % event.duration} "
|
||||||
|
log_string << " (#{additions.join(" | ")})" unless additions.blank?
|
||||||
|
|
||||||
|
info(log_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue