module DebugLogging
#
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]) # Provides the `logged` method decorator 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 #
From: stackoverflow.com/a/34559282 License: creativecommons.org/licenses/by-sa/4.0/
Constants
- VERSION
Attributes
debug_logging_configuration[RW]
Public Class Methods
configuration()
click to toggle source
For single statement global config in an initializer e.g. DebugLogging.configuration
.ellipsis = “…”
# File lib/debug_logging.rb, line 82 def self.configuration self.debug_logging_configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
For global config in an initializer with a block
# File lib/debug_logging.rb, line 87 def self.configure yield(configuration) end
extended(base)
click to toggle source
# File lib/debug_logging.rb, line 66 def self.extended(base) base.send(:extend, ArgumentPrinter) base.send(:extend, ApiClassMethods) base.send(:extend, ConfigClassMethods) base.debug_config_reset(Configuration.new(**debug_logging_configuration.to_hash)) base.class_eval do def base.inherited(subclass) subclass.debug_config_reset(Configuration.new(**debug_config.to_hash)) end end end