kenny 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2740dfe3834c07d205a400e43ed53ffaa70b3eb6
4
- data.tar.gz: cae861c957fb393d01fd56fa408d34f4d82ff725
3
+ metadata.gz: 6c2ee30aef4af126bb892a5a682a158524d9b4a9
4
+ data.tar.gz: 44854a85ae4e02a773594c6f5bb547aa86336ff4
5
5
  SHA512:
6
- metadata.gz: 180faaefd1c6d219bf0dd5e854dd8b2a9870103d746b83c1ecc622570777bb78762026290cf145d5837b76fdb92013122c177cdbaab1498ddbf373b93cc308e5
7
- data.tar.gz: 588c0abb9b75569892e9d51dcb1691725780e6d72d7e3efb931a7a50cb9d612719bbf2441fd36c4e427cb80b7a71ae1e2c2f2e8b5fef3ad1a24bbbc649a8d7ae
6
+ metadata.gz: c6972fc555f77201aca2c86bf855a43c287ed419b01ecdc5fc7482476133323d5a2cdd7d00514a5a24241dc06c4f5e8d3e0c9a2ea5fab964b382c5141567bb26
7
+ data.tar.gz: 689f0b1c8d4c8d74e871ebf99f66f43140c15aa264e0f7c42ef4edd426ae0ab54aeaa233eccbf6099bfa72f885dd7c6af9dc8a680edcbf768a969e96f4eedb76
data/README.md CHANGED
@@ -12,7 +12,6 @@ It allows the user to decide:
12
12
  - which instrumentations to monitor
13
13
  - what to do when the specified instrumentation event occurs
14
14
  - where to log the data to (or no logging to file at all)
15
- - whether or not to unsubscribe from Rails' default instrumentations (although not recommended)
16
15
 
17
16
  Apart from that, it was also created with the idea of keeping all subscribed events in one place. So it will keep your code clean and provide a nice overview of all event-triggered actions.
18
17
 
@@ -50,8 +49,6 @@ Or command line:
50
49
  log_stash_formatter = Kenny::Formatters::LogStashFormatter.new
51
50
  request_logger.formatter = log_stash_formatter
52
51
 
53
- config.kenny.unsubscribe_rails_defaults = false
54
- config.kenny.suppress_rack_logger = true
55
52
  config.kenny.instrumentations = [
56
53
  { name: 'process_action.action_controller',
57
54
  block: lambda do |event|
@@ -125,33 +122,6 @@ Or command line:
125
122
  You might think that since no `:logger` option has been provided for 'sql.active_record' events, the default logger will be used..... But that is not true.
126
123
  Since `logger` is within scope at the time when the lambda was defined, this instance of ActiveSupport::Logger will be used to invoke `#info` when 'sql.active_record' occurs. So just avoid creating a local variable that have the same name as variables in your block.
127
124
 
128
-
129
- ### `kenny.unsubscribe_rails_defaults` configuration
130
- Kenny can also used to unsubscribe all Rails LogSubscribers from their subscribed instrumentation events.
131
- You can do that by setting `:unsubscribe_rails_defaults` to true:
132
-
133
- ``` Ruby
134
- config.kenny.unsubscribe_rails_defaults = true
135
- config.kenny.instrumentations = [{
136
- # your stuff
137
- }]
138
- }
139
- ```
140
-
141
- By doing so, your `development|test|staging|production.log` will not have any of the default log messages. This is not an approach I would recommend, unless you are desperate to have all messages from your specified instrumentation events all logged into one `development|test|staging|production.log`.
142
-
143
-
144
- ### `kenny.suppress_rack_logger` configuration
145
- By default, your rails app logs messages like these to your environment's log:
146
-
147
- ```
148
- Started GET "/my_path" for 10.0.2.2 at 2016-07-12 10:06:48 +0000
149
- Started GET "/assets/sh/my_styles.css?body=1" for 10.0.2.2 at 2016-07-12 10:06:49 +0000
150
- ```
151
-
152
- You can suppress these messages by setting kenny.suppress_rack_logger to true.
153
- This setting will not have any effects on the log files that you create separately with the `:logger` option within your specified instrumentation.
154
-
155
125
  ## Open-to-Implementation approach
156
126
  As you might have seen from the example, the `:block` allows you to define your own implementation.
157
127
  The idea behind writing this gem is to free up users from the tedious task of defining LogSubscriber classes and to allow them to define whatever they wants to do with the event data, be it something like:
data/lib/kenny/railtie.rb CHANGED
@@ -17,12 +17,6 @@ module Kenny
17
17
  # perform the user-defined actions when that instrumentation occurs.
18
18
  # If desired, user can define a specific logger for the specified instrumentation.
19
19
  Kenny.attach_to_instrumentations
20
-
21
- # Unsubscribe all default Rails LogSubscribers if demanded
22
- Kenny.unsubscribe_from_rails_defaults
23
-
24
- # Suppress Rails::Rack::Logger's output
25
- Kenny.suppress_rack_logger
26
20
  end
27
21
  end
28
22
  end
data/lib/kenny.rb CHANGED
@@ -1,16 +1,11 @@
1
1
  ##
2
2
 
3
- # Kenny module does three things:
3
+ # Kenny module does two things:
4
4
  # - Holds reference to the Rails application (set through Railtie)
5
- # - Unsubscribe all Rails' LogSubscribers from the default instrumentation channels
6
5
  # - Create LogSubscriber-classes which will be attached to the user-specified instrumentations
7
6
  module Kenny
8
7
  def self.configs
9
- Struct.new(
10
- :unsubscribe_rails_defaults,
11
- :suppress_rack_logger,
12
- :instrumentations
13
- ).new
8
+ Struct.new(:instrumentations).new
14
9
  end
15
10
 
16
11
  def self.application=(app)
@@ -32,25 +27,6 @@ module Kenny
32
27
  end
33
28
  end
34
29
 
35
- ##
36
- # Unsubscribe all Rails' default LogSubscribers from the default Rails instrumentations,
37
- # by delegating to Kenny::Unsubscriber.
38
- # See http://edgeguides.rubyonrails.org/active_support_instrumentation.html
39
- def self.unsubscribe_from_rails_defaults
40
- if @application.config.kenny[:unsubscribe_rails_defaults]
41
- Kenny::Unsubscriber.unsubscribe_from_rails_defaults
42
- end
43
- end
44
-
45
- ##
46
- # Suppress Rails::Rack::Logger's output like:
47
- # Started GET "/my_path" for 10.0.2.2 at 2016-07-12 10:06:48 +0000
48
- def self.suppress_rack_logger
49
- if @application.config.kenny[:suppress_rack_logger]
50
- require 'kenny/rails_ext/rack/logger'
51
- end
52
- end
53
-
54
30
  ##
55
31
  # Create LogSubscriber-classes which will be attached to the user-specified instrumentations
56
32
  # These classes are anonymous, but inherit from Kenny::LogSubscriber to simplify testing
@@ -77,5 +53,4 @@ end
77
53
  require 'kenny/railtie'
78
54
 
79
55
  require 'kenny/formatters/log_stash_formatter'
80
- require 'kenny/unsubscriber'
81
56
  require 'kenny/log_subscriber'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kenny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Rüdiger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-20 00:00:00.000000000 Z
12
+ date: 2016-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -181,9 +181,7 @@ files:
181
181
  - lib/kenny.rb
182
182
  - lib/kenny/formatters/log_stash_formatter.rb
183
183
  - lib/kenny/log_subscriber.rb
184
- - lib/kenny/rails_ext/rack/logger.rb
185
184
  - lib/kenny/railtie.rb
186
- - lib/kenny/unsubscriber.rb
187
185
  homepage: https://github.com/fromAtoB/kenny
188
186
  licenses:
189
187
  - MIT
@@ -1,25 +0,0 @@
1
- require 'active_support/concern'
2
- require 'rails/rack/logger'
3
-
4
- module Rails
5
- module Rack
6
- # Overwrites defaults of Rails::Rack::Logger that cause
7
- # unnecessary logging.
8
- # This effectively removes the log lines from the log
9
- # that say:
10
- # Started GET / for 192.168.2.1...
11
- class Logger
12
- # Overwrites Rails 3.2 code that logs new requests
13
- def call_app(*args)
14
- env = args.last
15
- @app.call(env)
16
- ensure
17
- ActiveSupport::LogSubscriber.flush_all!
18
- end
19
-
20
- # Overwrites Rails 3.0/3.1 code that logs new requests
21
- def before_dispatch(_env)
22
- end
23
- end
24
- end
25
- end
@@ -1,64 +0,0 @@
1
- ##
2
- module Kenny
3
- # Module to unsubscribe all Rails default LogSubscribers from their events.
4
- module Unsubscriber
5
- DEFAULT_RAILS_LOG_SUBSCRIBER_CLASSES = [
6
- ActionView::LogSubscriber,
7
- ActionController::LogSubscriber,
8
- ActiveRecord::LogSubscriber,
9
- ActionMailer::LogSubscriber
10
- ].freeze
11
-
12
- ##
13
- # By default, a Rails app instantiates the LogSubscribers listed above and
14
- # are actively listening to instrumentations listed in:
15
- # http://edgeguides.rubyonrails.org/active_support_instrumentation.html
16
- #
17
- # Unsubscribing is not recommended, unless you want to modify the output
18
- # to your standard rails logs (development|test|staging|production).log
19
- #
20
- # It would be safer to write your chosen instrumentation data to a separate file,
21
- # setup by the [:logger] configuration (see Readme).
22
-
23
- # In that case, the [:unsubscribe_rails_defaults]
24
- # field in Kenny's config won't need to be set.
25
- def self.unsubscribe_from_rails_defaults
26
- default_rails_log_subscribers.each do |subscriber|
27
- subscribed_events_for(subscriber).each do |event|
28
- unsubscribe_listeners_for_event(subscriber, event)
29
- end
30
- end
31
- end
32
-
33
- def self.default_rails_log_subscribers
34
- ActiveSupport::LogSubscriber.log_subscribers.select do |subscriber|
35
- DEFAULT_RAILS_LOG_SUBSCRIBER_CLASSES.include? subscriber.class
36
- end
37
- end
38
- private_class_method :default_rails_log_subscribers
39
-
40
- def self.listeners_for(event, subscriber_namespace)
41
- ActiveSupport::Notifications.notifier.listeners_for(
42
- "#{event}.#{subscriber_namespace}"
43
- )
44
- end
45
- private_class_method :listeners_for
46
-
47
- def self.unsubscribe_listeners_for_event(subscriber, event)
48
- subscriber_namespace = subscriber.class.send :namespace
49
- listeners_for(event, subscriber_namespace).each do |listener|
50
- if listener.instance_variable_get('@delegate') == subscriber
51
- ActiveSupport::Notifications.unsubscribe listener
52
- end
53
- end
54
- end
55
- private_class_method :unsubscribe_listeners_for_event
56
-
57
- def self.subscribed_events_for(subscriber)
58
- error_msg = "Expected #{subscriber} to be inherited from ActiveSupport::LogSubscriber"
59
- raise error_msg if subscriber.class.superclass != ActiveSupport::LogSubscriber
60
- subscriber.public_methods(false).reject { |method| method.to_s == 'call' }
61
- end
62
- private_class_method :subscribed_events_for
63
- end
64
- end