@@ -18,26 +18,20 @@ module ActiveSupport
18
18
#
19
19
# module ActiveRecord
20
20
# class LogSubscriber < ActiveSupport::LogSubscriber
21
+ # attach_to :active_record
22
+ #
21
23
# def sql(event)
22
24
# info "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
23
25
# end
24
26
# end
25
27
# end
26
28
#
27
- # And it's finally registered as:
28
- #
29
- # ActiveRecord::LogSubscriber.attach_to :active_record
30
- #
31
- # Since we need to know all instance methods before attaching the log
32
- # subscriber, the line above should be called after your
33
- # <tt>ActiveRecord::LogSubscriber</tt> definition.
34
- #
35
- # A logger also needs to be set with <tt>ActiveRecord::LogSubscriber.logger=</tt>.
36
- # This is assigned automatically in a Rails environment.
29
+ # ActiveRecord::LogSubscriber.logger must be set as well, but it is assigned
30
+ # automatically in a \Rails environment.
37
31
#
38
- # After configured, whenever a <tt>"sql.active_record"</tt> notification is published,
39
- # it will properly dispatch the event
40
- # (<tt> ActiveSupport::Notifications::Event</tt> ) to the sql method.
32
+ # After configured, whenever a <tt>"sql.active_record"</tt> notification is
33
+ # published, it will properly dispatch the event
34
+ # (ActiveSupport::Notifications::Event) to the + sql+ method.
41
35
#
42
36
# Being an ActiveSupport::Notifications consumer,
43
37
# <tt>ActiveSupport::LogSubscriber</tt> exposes a simple interface to check if
@@ -62,9 +56,10 @@ module ActiveSupport
62
56
# end
63
57
# end
64
58
#
65
- # Log subscriber also has some helpers to deal with logging and automatically
66
- # flushes all logs when the request finishes
67
- # (via <tt>action_dispatch.callback</tt> notification) in a Rails environment.
59
+ # <tt>ActiveSupport::LogSubscriber</tt> also has some helpers to deal with
60
+ # logging. For example, ActiveSupport::LogSubscriber.flush_all! will ensure
61
+ # that all logs are flushed, and it is called in Rails::Rack::Logger after a
62
+ # request finishes.
68
63
class LogSubscriber < Subscriber
69
64
# Embed in a String to clear all previous ANSI sequences.
70
65
CLEAR = ActiveSupport ::Deprecation ::DeprecatedObjectProxy . new ( "\e [0m" , "CLEAR is deprecated! Use MODES[:clear] instead." , ActiveSupport . deprecator )
0 commit comments