Class: DebugLogging::Configuration

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/debug_logging/configuration.rb

Constant Summary

Constants included from Constants

DebugLogging::Constants::CONFIG_ATTRS, DebugLogging::Constants::CONFIG_ATTRS_DEFAULTS, DebugLogging::Constants::CONFIG_KEYS, DebugLogging::Constants::CONFIG_READERS, DebugLogging::Constants::CONFIG_READERS_DEFAULTS, DebugLogging::Constants::DEFAULT_ELLIPSIS, DebugLogging::Constants::DEFAULT_TIME_FORMATTER, DebugLogging::Constants::EVENT_TIME_FORMATTER

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Configuration

Returns a new instance of Configuration.



49
50
51
52
53
54
55
56
57
# File 'lib/debug_logging/configuration.rb', line 49

def initialize(**options)
  CONFIG_ATTRS.each do |key|
    send(:"#{key}=", get_attr_from_options(options, key))
  end
  CONFIG_READERS.each do |key|
    send(:"#{key}=", get_reader_from_options(options, key))
  end
  @methods_to_log = []
end

Class Method Details

.config_pointer(type, method_to_log) ⇒ Object



41
42
43
44
45
46
# File 'lib/debug_logging/configuration.rb', line 41

def config_pointer(type, method_to_log)
  # Methods names that do not match the following regex can't be part of an ivar name
  #   /[a-zA-Z_][a-zA-Z0-9_]*/
  # Thus we have to use a different form of the method name that is compatible with ivar name conventions
  "@debug_logging_config_#{type}_#{Digest::MD5.hexdigest(method_to_log.to_s)}".to_sym
end

Instance Method Details

#active_support_notifications=(active_support_notifications) ⇒ Object



98
99
100
101
# File 'lib/debug_logging/configuration.rb', line 98

def active_support_notifications=(active_support_notifications)
  require "debug_logging/active_support_notifications" if active_support_notifications
  @active_support_notifications = active_support_notifications
end

#benchmarkable_for?(benchmarks) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
80
# File 'lib/debug_logging/configuration.rb', line 76

def benchmarkable_for?(benchmarks)
  return @benchmarkable if defined?(@benchmarkable)

  @benchmarkable = loggable? && send(benchmarks)
end

#class_benchmarks=(class_benchmarks) ⇒ Object



93
94
95
96
# File 'lib/debug_logging/configuration.rb', line 93

def class_benchmarks=(class_benchmarks)
  require "benchmark" if class_benchmarks
  @class_benchmarks = class_benchmarks
end

#exit_scope_markable?Boolean

Returns:

  • (Boolean)


82
83
84
85
86
# File 'lib/debug_logging/configuration.rb', line 82

def exit_scope_markable?
  return @exit_scope_markable if defined?(@exit_scope_markable)

  @exit_scope_markable = loggable? && mark_scope_exit
end

#instance_benchmarks=(instance_benchmarks) ⇒ Object



88
89
90
91
# File 'lib/debug_logging/configuration.rb', line 88

def instance_benchmarks=(instance_benchmarks)
  require "benchmark" if instance_benchmarks
  @instance_benchmarks = instance_benchmarks
end

#log(message = nil, &block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/debug_logging/configuration.rb', line 59

def log(message = nil, &block)
  return unless enabled
  return unless logger

  if block
    logger.send(log_level, &block)
  else
    logger.send(log_level, message)
  end
end

#loggable?Boolean

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/debug_logging/configuration.rb', line 70

def loggable?
  return @loggable if defined?(@loggable)

  @loggable = logger.send(:"#{log_level}?")
end

#register(method_lo_log) ⇒ Object



109
110
111
# File 'lib/debug_logging/configuration.rb', line 109

def register(method_lo_log)
  @methods_to_log << method_lo_log
end

#to_hashObject



103
104
105
106
107
# File 'lib/debug_logging/configuration.rb', line 103

def to_hash
  CONFIG_KEYS.each_with_object({}) do |key, hash|
    hash[key] = instance_variable_get(:"@#{key}")
  end
end