Module: Kenny

Defined in:
lib/kenny.rb,
lib/kenny/railtie.rb,
lib/kenny/unsubscriber.rb,
lib/kenny/log_subscriber.rb,
lib/kenny/formatters/log_stash_formatter.rb

Overview

This class is meant to be inherited by anonymous classes, created through Kenny.define_log_subscriber_class.

By inserting this class into the inheritance tree, we can verify in test-environment whether the LogSubscribers we created are indeed attached to the instrumentations we specified.

Defined Under Namespace

Modules: Formatters, Unsubscriber Classes: LogSubscriber, Railtie

Class Method Summary collapse

Class Method Details

.applicationObject



21
22
23
# File 'lib/kenny.rb', line 21

def self.application
  @@application
end

.application=(app) ⇒ Object



17
18
19
# File 'lib/kenny.rb', line 17

def self.application=(app)
  @@application = app
end

.attach_to_instrumentationsObject

Define LogSubscriber-classes and Attach to user-specified instrumentations if the configurations have been set.



28
29
30
31
32
33
34
# File 'lib/kenny.rb', line 28

def self.attach_to_instrumentations
  if @@application.config.kenny[:instrumentations]
    @@application.config.kenny[:instrumentations].each do |instr_config|
      define_log_subscriber_class(instr_config)
    end
  end
end

.configsObject



9
10
11
12
13
14
15
# File 'lib/kenny.rb', line 9

def self.configs
  Struct.new(
    :unsubscribe_rails_defaults,
    :suppress_rack_logger,
    :instrumentations
  ).new
end

.suppress_rack_loggerObject

Suppress Rails::Rack::Logger’s output à la

Started GET "/my_path" for 10.0.2.2 at 2016-07-12 10:06:48 +0000


49
50
51
52
53
# File 'lib/kenny.rb', line 49

def self.suppress_rack_logger
  if @@application.config.kenny[:suppress_rack_logger]
    require "kenny/rails_ext/rack/logger"
  end
end

.unsubscribe_from_rails_defaultsObject

Unsubscribe all Rails’ default LogSubscribers from the default Rails instrumentations, by delegating to Kenny::Unsubscriber. See edgeguides.rubyonrails.org/active_support_instrumentation.html



40
41
42
43
44
# File 'lib/kenny.rb', line 40

def self.unsubscribe_from_rails_defaults
  if @@application.config.kenny[:unsubscribe_rails_defaults]
    Kenny::Unsubscriber.unsubscribe_from_rails_defaults
  end
end