Module: DebugLogging

Defined in:
lib/debug_logging.rb,
lib/debug_logging/version.rb,
lib/debug_logging/class_logger.rb,
lib/debug_logging/configuration.rb,
lib/debug_logging/instance_logger.rb,
lib/debug_logging/argument_printer.rb,
lib/debug_logging/instance_logger_modulizer.rb

Overview

# NOTE: The manner this is made to work for class methods is totally different

than the way this is made to work for instance methods.

NOTE: The instance method manner works on Ruby 2.0+ NOTE: The class method manner works on Ruby 2.1+

#

#

USAGE (see specs)#

             #
class Car

  # adds the helper methods to the class, all are prefixed with debug_*,
  #   except for the logged class method, which comes from extending DebugLogging::ClassLogger
  extend DebugLogging

  # per class configuration overrides!
  self.debug_class_benchmarks = true
  self.debug_instance_benchmarks = true

  # For instance methods:
  # Option 1: specify the exact method(s) to add logging to
  include DebugLogging::InstanceLogger.new(i_methods: [:drive, :stop])

  extend DebugLogging::ClassLogger

  logged def debug_make; new; end
  def design(*args); new; end
  def safety(*args); new; end
  logged :design, :safety

  def drive(speed); speed; end
  def stop; 0; end

  # For instance methods:
  # Option 2: add logging to all instance methods defined above (but *not* defined below)
  include DebugLogging::InstanceLogger.new(i_methods: debug_instance_methods(false))

  def will_not_be_logged; false; end

end
             #

Defined Under Namespace

Modules: ArgumentPrinter, ClassLogger, InstanceLoggerModulizer Classes: Configuration, InstanceLogger

Constant Summary collapse

VERSION =
"1.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.debug_logging_configurationObject

Returns the value of attribute debug_logging_configuration.



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

def debug_logging_configuration
  @debug_logging_configuration
end

Class Method Details

.configurationObject

For single statement global config in an initializer e.g. DebugLogging.configuration.ellipsis = “…”



67
68
69
# File 'lib/debug_logging.rb', line 67

def self.configuration
  self.debug_logging_configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

For global config in an initializer with a block

Yields:



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

def self.configure
  yield(configuration)
end

.extended(base) ⇒ Object



55
56
57
58
# File 'lib/debug_logging.rb', line 55

def self.extended(base)
  base.send(:extend, ArgumentPrinter)
  base.debug_config_reset(debug_logging_configuration.dup)
end

Instance Method Details

#debug_add_invocation_idObject



131
132
133
# File 'lib/debug_logging.rb', line 131

def debug_add_invocation_id
  @debug_logging_configuration.add_invocation_id
end

#debug_add_invocation_id=(add_invocation_id) ⇒ Object



134
135
136
# File 'lib/debug_logging.rb', line 134

def debug_add_invocation_id=(add_invocation_id)
  @debug_logging_configuration.add_invocation_id = add_invocation_id
end

#debug_args_max_lengthObject



113
114
115
# File 'lib/debug_logging.rb', line 113

def debug_args_max_length
  @debug_logging_configuration.args_max_length
end

#debug_args_max_length=(args_max_length) ⇒ Object



116
117
118
# File 'lib/debug_logging.rb', line 116

def debug_args_max_length=(args_max_length)
  @debug_logging_configuration.args_max_length = args_max_length
end

#debug_class_benchmarksObject



125
126
127
# File 'lib/debug_logging.rb', line 125

def debug_class_benchmarks
  @debug_logging_configuration.class_benchmarks
end

#debug_class_benchmarks=(class_benchmarks) ⇒ Object



128
129
130
# File 'lib/debug_logging.rb', line 128

def debug_class_benchmarks=(class_benchmarks)
  @debug_logging_configuration.class_benchmarks = class_benchmarks
end

#debug_config_reset(config = Configuration.new) ⇒ Object



86
87
88
# File 'lib/debug_logging.rb', line 86

def debug_config_reset(config = Configuration.new)
  @debug_logging_configuration = config
end

#debug_ellipsisObject



137
138
139
# File 'lib/debug_logging.rb', line 137

def debug_ellipsis
  @debug_logging_configuration.ellipsis
end

#debug_ellipsis=(ellipsis) ⇒ Object



140
141
142
# File 'lib/debug_logging.rb', line 140

def debug_ellipsis=(ellipsis)
  @debug_logging_configuration.ellipsis = ellipsis
end

#debug_instance_benchmarksObject



119
120
121
# File 'lib/debug_logging.rb', line 119

def debug_instance_benchmarks
  @debug_logging_configuration.instance_benchmarks
end

#debug_instance_benchmarks=(instance_benchmarks) ⇒ Object



122
123
124
# File 'lib/debug_logging.rb', line 122

def debug_instance_benchmarks=(instance_benchmarks)
  @debug_logging_configuration.instance_benchmarks = instance_benchmarks
end

#debug_last_hash_max_lengthObject



107
108
109
# File 'lib/debug_logging.rb', line 107

def debug_last_hash_max_length
  @debug_logging_configuration.last_hash_max_length
end

#debug_last_hash_max_length=(last_hash_max_length) ⇒ Object



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

def debug_last_hash_max_length=(last_hash_max_length)
  @debug_logging_configuration.last_hash_max_length = last_hash_max_length
end

#debug_last_hash_to_s_procObject



101
102
103
# File 'lib/debug_logging.rb', line 101

def debug_last_hash_to_s_proc
  @debug_logging_configuration.last_hash_to_s_proc
end

#debug_last_hash_to_s_proc=(last_hash_to_s_proc) ⇒ Object



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

def debug_last_hash_to_s_proc=(last_hash_to_s_proc)
  @debug_logging_configuration.last_hash_to_s_proc = last_hash_to_s_proc
end

#debug_log(message) ⇒ Object

API ####



61
62
63
# File 'lib/debug_logging.rb', line 61

def debug_log(message)
  debug_logger.send(debug_log_level, message)
end

#debug_log_levelObject



95
96
97
# File 'lib/debug_logging.rb', line 95

def debug_log_level
  @debug_logging_configuration.log_level
end

#debug_log_level=(log_level) ⇒ Object



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

def debug_log_level=(log_level)
  @debug_logging_configuration.log_level = log_level
end

#debug_loggerObject



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

def debug_logger
  @debug_logging_configuration.logger
end

#debug_logger=(logger) ⇒ Object



92
93
94
# File 'lib/debug_logging.rb', line 92

def debug_logger=(logger)
  @debug_logging_configuration.logger = logger
end

#debug_logging_configure {|@debug_logging_configuration| ... } ⇒ Object

For per-class config with a block



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

def debug_logging_configure
  @debug_logging_configuration ||= Configuration.new
  yield(@debug_logging_configuration)
end