class ITrace::LogSwitch
Attributes
logger[R]
Public Class Methods
new(logger, enable_logging = true)
click to toggle source
# File lib/itrace/log_switch.rb, line 5 def initialize(logger, enable_logging = true) @logger = logger @logger_methods = {} @enable_logging = enable_logging end
Public Instance Methods
call_logger(m_id, *args, &blk)
click to toggle source
# File lib/itrace/log_switch.rb, line 21 def call_logger(m_id, *args, &blk) get_logger_method(m_id).call(*args, &blk) if @enable_logging end
change_logger(logger)
click to toggle source
# File lib/itrace/log_switch.rb, line 25 def change_logger(logger) raise NotYetImplementedError end
disable_logging()
click to toggle source
# File lib/itrace/log_switch.rb, line 16 def disable_logging @enable_logging = false self end
enable_logging()
click to toggle source
# File lib/itrace/log_switch.rb, line 11 def enable_logging @enable_logging = true self end
Private Instance Methods
create_wrapper_method(m_id)
click to toggle source
# File lib/itrace/log_switch.rb, line 38 def create_wrapper_method(m_id) logger_method = get_logger_method(m_id) define_singleton_method(m_id) do |*args, &blk| logger_method.call(*args, &blk) if @enable_logging end singleton_method(m_id) end
get_logger_method(m_id)
click to toggle source
# File lib/itrace/log_switch.rb, line 34 def get_logger_method(m_id) @logger_methods[m_id] ||= @logger.method(m_id) end
method_missing(m_id, *args, &blk)
click to toggle source
# File lib/itrace/log_switch.rb, line 48 def method_missing(m_id, *args, &blk) create_wrapper_method(m_id).call(*args, &blk) end