time_bandits 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,15 +8,7 @@ module ActionController #:nodoc:
8
8
  # patch to ensure that the completed line is always written to the log
9
9
  def process_action(action, *args)
10
10
 
11
- raw_payload = {
12
- :controller => self.class.name,
13
- :action => self.action_name,
14
- :params => request.filtered_parameters,
15
- :formats => request.formats.map(&:to_sym),
16
- :method => request.method,
17
- :path => (request.fullpath rescue "unknown")
18
- }
19
-
11
+ raw_payload = get_raw_payload(action)
20
12
  ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup)
21
13
 
22
14
  exception = nil
@@ -59,6 +51,34 @@ module ActionController #:nodoc:
59
51
  runtime - consumed_during_rendering*1000
60
52
  end
61
53
 
54
+ private
55
+
56
+ if Rails::VERSION::STRING =~ /^3\.2/
57
+ def get_raw_payload(action)
58
+ {
59
+ :controller => self.class.name,
60
+ :action => self.action_name,
61
+ :params => request.filtered_parameters,
62
+ :formats => request.formats.map(&:to_sym),
63
+ :method => request.method,
64
+ :path => (request.fullpath rescue "unknown")
65
+ }
66
+ end
67
+ elsif Rails::VERSION::STRING =~ /^3\.[01]/
68
+ def get_raw_payload(action)
69
+ {
70
+ :controller => self.class.name,
71
+ :action => self.action_name,
72
+ :params => request.filtered_parameters,
73
+ :format => request.format.try(:ref),
74
+ :method => request.method,
75
+ :path => (request.fullpath rescue "unknown")
76
+ }
77
+ end
78
+ else
79
+ raise "time_bandits ActionController monkey patch is not compatible with your Rails version"
80
+ end
81
+
62
82
  module ClassMethods
63
83
  def log_process_action(payload) #:nodoc:
64
84
  messages, view_runtime = [], payload[:view_runtime]
@@ -3,8 +3,8 @@
3
3
  # and the number of query cache hits
4
4
  # it needs to be adapted to each new rails version
5
5
 
6
- raise "AR log subscriber monkey patch for custom benchmarking is not compatible with your rails version" unless
7
- (Rails::VERSION::STRING > "3.0" && Rails::VERSION::STRING < "3.1")
6
+ raise "time_bandits ActiveRecord monkey patch is not compatible with your rails version" unless
7
+ Rails::VERSION::STRING =~ /^3\.[012]/
8
8
 
9
9
  require "active_record/log_subscriber"
10
10
 
@@ -46,8 +46,19 @@ module ActiveRecord
46
46
 
47
47
  return unless logger.debug?
48
48
 
49
- name = '%s (%.1fms)' % [event.payload[:name], event.duration]
50
- sql = event.payload[:sql].squeeze(' ')
49
+ payload = event.payload
50
+
51
+ return if 'SCHEMA' == payload[:name]
52
+
53
+ name = '%s (%.1fms)' % [payload[:name], event.duration]
54
+ sql = payload[:sql].squeeze(' ')
55
+ binds = nil
56
+
57
+ unless (payload[:binds] || []).empty?
58
+ binds = " " + payload[:binds].map { |col,v|
59
+ [col.name, v]
60
+ }.inspect
61
+ end
51
62
 
52
63
  if odd?
53
64
  name = color(name, CYAN, true)
@@ -56,7 +67,7 @@ module ActiveRecord
56
67
  name = color(name, MAGENTA, true)
57
68
  end
58
69
 
59
- debug " #{name} #{sql}"
70
+ debug " #{name} #{sql}#{binds}"
60
71
  end
61
72
  end
62
73
 
@@ -1,7 +1,8 @@
1
1
  module TimeBandits
2
2
  module Rack
3
3
  class Logger < ActiveSupport::LogSubscriber
4
- def initialize(app)
4
+ # TODO: how to deal with tags
5
+ def initialize(app, tags=nil)
5
6
  @app = app
6
7
  end
7
8
 
@@ -20,10 +21,9 @@ module TimeBandits
20
21
  Thread.current[:time_bandits_completed_info] = nil
21
22
 
22
23
  request = ActionDispatch::Request.new(env)
23
- path = request.fullpath
24
+ path = request.filtered_path
24
25
 
25
- info "\n\nStarted #{request.request_method} \"#{path}\" " \
26
- "for #{request.ip} at #{start_time.to_default_s}"
26
+ info "\n\nStarted #{request.request_method} \"#{path}\" for #{request.ip} at #{start_time.to_default_s}"
27
27
  end
28
28
 
29
29
  def after_dispatch(env, result, run_time)
@@ -33,7 +33,7 @@ module TimeBandits
33
33
  message = "Completed #{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]} in %.1fms" % (run_time*1000)
34
34
  message << " (#{additions.join(' | ')})" unless additions.blank?
35
35
  info message
36
-
36
+ ensure
37
37
  ActiveSupport::LogSubscriber.flush_all!
38
38
  end
39
39
 
@@ -1,11 +1,15 @@
1
1
  module TimeBandits
2
+
3
+ module Rack
4
+ autoload :Logger, 'time_bandits/rack/logger'
5
+ end
6
+
2
7
  class Railtie < Rails::Railtie
3
8
 
4
9
  initializer "time_bandits" do |app|
5
10
  app.config.middleware.swap("Rails::Rack::Logger", "TimeBandits::Rack::Logger")
6
11
 
7
12
  ActiveSupport.on_load(:action_controller) do
8
- require 'time_bandits/rack/logger.rb'
9
13
  require 'time_bandits/monkey_patches/action_controller'
10
14
  include ActionController::TimeBanditry
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module TimeBandits
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_bandits
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stefan Kaes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-27 00:00:00 +01:00
18
+ date: 2012-04-05 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency