Module: TransactionLogger::ClassMethods
- Defined in:
- lib/transaction_logger.rb
Instance Method Summary collapse
-
#add_transaction_log(method, options = {}) ⇒ Object
Registers a method with the TransactionLogger, which will begin tracking the logging within the method and it's nested methods.
Instance Method Details
#add_transaction_log(method, options = {}) ⇒ Object
Registers a method with the TransactionLogger, which will begin tracking the logging within the method and it's nested methods. These logs are collected under one transaction, and if the level threshold is broken or when an error is raised, the collected logs are pushed to the configured logger as a JSON hash.
By registering multiple methods as transactions, each method becomes it's own transaction.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/transaction_logger.rb', line 28 def add_transaction_log(method, ={}) old_method = instance_method method = {} [:prefix] = TransactionLogger::Configure.instance_variable_get :@prefix [:logger] = TransactionLogger::Configure.instance_variable_get :@logger [:level_threshold] = TransactionLogger::Configure.instance_variable_get :@level_threshold define_method method do TransactionManager.start , lambda { |transaction| transaction.name = [:name] transaction.name ||= "#{old_method.bind(self).owner}#{method.inspect}" transaction.context = [:context] transaction.context ||= {} # Check for a logger on the instance if methods.include? :logger logger_method = method(:logger).unbind # Check for a logger on the class elsif self.class.methods.include? :logger logger_method = self.class.method :logger end # Trap the logger if we've found one if logger_method method_info = {} method_info[:logger_method] = logger_method method_info[:calling_method] = caller_locations(1, 1)[0].label method_info[:includer] = self TransactionLogger::Helper.trap_logger method, transaction, method_info end old_method.bind(self).call } end end |