Class: Flipper::Instrumentation::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/flipper/instrumentation/log_subscriber.rb

Instance Method Summary collapse

Instance Method Details

#adapter_operation(event) ⇒ Object

Logs an adapter operation. If operation is for a feature, then that feature is included in log output.

Example Output

# log output for adapter operation with feature
# Flipper feature(search) adapter(memory) enable  (0.0ms)  [ result=...]

# log output for adapter operation with no feature
# Flipper adapter(memory) features (0.0ms)  [ result=... ]

Returns nothing.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/flipper/instrumentation/log_subscriber.rb', line 48

def adapter_operation(event)
  return unless logger.debug?

  feature_name = event.payload[:feature_name]
  adapter_name = event.payload[:adapter_name]
  gate_name = event.payload[:gate_name]
  operation = event.payload[:operation]
  result = event.payload[:result]

  description = "Flipper "
  description << "feature(#{feature_name}) " unless feature_name.nil?
  description << "adapter(#{adapter_name}) "
  description << "#{operation} "

  details = "result=#{result.inspect}"

  name = '%s (%.1fms)' % [description, event.duration]
  debug "  #{color(name, CYAN, true)}  [ #{details} ]"
end

#feature_operation(event) ⇒ Object

Logs a feature operation.

Example Output

flipper[:search].enabled?(user)
# Flipper feature(search) enabled? false (1.2ms)  [ thing=... ]

Returns nothing.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/flipper/instrumentation/log_subscriber.rb', line 16

def feature_operation(event)
  return unless logger.debug?

  feature_name = event.payload[:feature_name]
  gate_name = event.payload[:gate_name]
  operation = event.payload[:operation]
  result = event.payload[:result]
  thing = event.payload[:thing]

  description = "Flipper feature(#{feature_name}) #{operation} #{result.inspect}"
  details = "thing=#{thing.inspect}"

  unless gate_name.nil?
    details += " gate_name=#{gate_name}"
  end

  name = '%s (%.1fms)' % [description, event.duration]
  debug "  #{color(name, CYAN, true)}  [ #{details} ]"
end

#loggerObject



68
69
70
# File 'lib/flipper/instrumentation/log_subscriber.rb', line 68

def logger
  self.class.logger
end