Sha256: f01d8e0af61b6e436c3e58abddbb957c066e07b34cf6e4817d888d5d9f093640
Contents?: true
Size: 1.48 KB
Versions: 3
Compression:
Stored size: 1.48 KB
Contents
module Services class Base module CallLogger def call(*args) return super if Services.configuration.logger.nil? log "START with args #{args}" log "CALLED BY #{caller || '(not found)'}" start = Time.now begin result = super rescue => e log_exception e raise e ensure log "END after #{(Time.now - start).round(2)} seconds" result end end private def log(message, severity = :info) Services.configuration.logger.log message, { service: self.class, id: @id }, severity end def log_exception(e, cause = false) log "#{'caused by: ' if cause}#{e.class}: #{e.message}" if e.respond_to?(:cause) && e.cause e.backtrace.take(5).each do |line| log " #{line}" end log_exception(e.cause, true) else e.backtrace.each do |line| log " #{line}" end end end def caller caller_location = caller_locations(1, 10).detect do |location| location.path !~ /\A#{Regexp.escape File.expand_path('../..', __FILE__)}/ end if caller_location.nil? nil else caller_path = caller_location.path caller_path = caller_path.sub(%r(\A#{Regexp.escape Rails.root.to_s}/), '') if defined?(Rails) [caller_path, caller_location.lineno].join(':') end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
services-1.2.0 | lib/services/modules/call_logger.rb |
services-1.1.1 | lib/services/modules/call_logger.rb |
services-1.1.0 | lib/services/modules/call_logger.rb |