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: self.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.7"

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.



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

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 = “…”



75
76
77
# File 'lib/debug_logging.rb', line 75

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

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

For global config in an initializer with a block

Yields:



80
81
82
# File 'lib/debug_logging.rb', line 80

def self.configure
  yield(configuration)
end

.extended(base) ⇒ Object



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

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

Instance Method Details

#debug_add_invocation_idObject



157
158
159
# File 'lib/debug_logging.rb', line 157

def debug_add_invocation_id
  @debug_logging_configuration.add_invocation_id
end

#debug_add_invocation_id=(add_invocation_id) ⇒ Object



160
161
162
# File 'lib/debug_logging.rb', line 160

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

#debug_args_max_lengthObject



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

def debug_args_max_length
  @debug_logging_configuration.args_max_length
end

#debug_args_max_length=(args_max_length) ⇒ Object



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

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

#debug_class_benchmarksObject



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

def debug_class_benchmarks
  @debug_logging_configuration.class_benchmarks
end

#debug_class_benchmarks=(class_benchmarks) ⇒ Object



142
143
144
# File 'lib/debug_logging.rb', line 142

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

#debug_colorized_chain_for_classObject



151
152
153
# File 'lib/debug_logging.rb', line 151

def debug_colorized_chain_for_class
  @debug_logging_configuration.colorized_chain_for_class
end

#debug_colorized_chain_for_class=(colorized_chain_for_class) ⇒ Object



154
155
156
# File 'lib/debug_logging.rb', line 154

def debug_colorized_chain_for_class=(colorized_chain_for_class)
  @debug_logging_configuration.colorized_chain_for_class = colorized_chain_for_class
end

#debug_colorized_chain_for_methodObject



145
146
147
# File 'lib/debug_logging.rb', line 145

def debug_colorized_chain_for_method
  @debug_logging_configuration.colorized_chain_for_method
end

#debug_colorized_chain_for_method=(colorized_chain_for_method) ⇒ Object



148
149
150
# File 'lib/debug_logging.rb', line 148

def debug_colorized_chain_for_method=(colorized_chain_for_method)
  @debug_logging_configuration.colorized_chain_for_method = colorized_chain_for_method
end

#debug_configObject

There are times when the class will need access to the configuration object,

such as to override it per instance method


69
70
71
# File 'lib/debug_logging.rb', line 69

def debug_config
  @debug_logging_configuration
end

#debug_config_reset(config = Configuration.new) ⇒ Object



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

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

#debug_ellipsisObject



163
164
165
# File 'lib/debug_logging.rb', line 163

def debug_ellipsis
  @debug_logging_configuration.ellipsis
end

#debug_ellipsis=(ellipsis) ⇒ Object



166
167
168
# File 'lib/debug_logging.rb', line 166

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

#debug_instance_benchmarksObject



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

def debug_instance_benchmarks
  @debug_logging_configuration.instance_benchmarks
end

#debug_instance_benchmarks=(instance_benchmarks) ⇒ Object



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

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

#debug_last_hash_max_lengthObject



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

def debug_last_hash_max_length
  @debug_logging_configuration.last_hash_max_length
end

#debug_last_hash_max_length=(last_hash_max_length) ⇒ Object



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

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



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

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



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

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, config_proxy = nil) ⇒ Object

API ####



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

def debug_log(message, config_proxy = nil)
  config_proxy ||= self
  config_proxy.debug_logger.send(config_proxy.debug_log_level, message) if config_proxy.debug_logger
end

#debug_log_levelObject



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

def debug_log_level
  @debug_logging_configuration.log_level
end

#debug_log_level=(log_level) ⇒ Object



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

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

#debug_loggerObject



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

def debug_logger
  @debug_logging_configuration.logger
end

#debug_logger=(logger) ⇒ Object



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

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

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

For per-class config with a block



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

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

#debug_multiple_last_hashesObject



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

def debug_multiple_last_hashes
  @debug_logging_configuration.multiple_last_hashes
end

#debug_multiple_last_hashes=(multiple_last_hashes) ⇒ Object



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

def debug_multiple_last_hashes=(multiple_last_hashes)
  @debug_logging_configuration.multiple_last_hashes = multiple_last_hashes
end