Sha256: 5586514ee0c41ce06a5f58d3a3ca2c22de42b590e2c41c67d0b5781f32d366f0
Contents?: true
Size: 1.88 KB
Versions: 7
Compression:
Stored size: 1.88 KB
Contents
# frozen_string_literal: true module PUNK module Loggable extend ActiveSupport::Concern def logger self.class.logger end def profile_info(name, **kwargs, &block) self.class.profile_info(name, **kwargs, &block) end def profile_debug(name, **kwargs, &block) self.class.profile_debug(name, **kwargs, &block) end def profile_trace(name, **kwargs, &block) self.class.profile_trace(name, **kwargs, &block) end def exception(e, extra={}) if ENV.key?('SENTRY_DSN') ::Sentry.capture_exception( e, message: e.message, extra: extra, transaction: "Punk!" ) end _clean(e) logger.error exception: e end private IGNORE = Gem.path + $LOAD_PATH def _clean(e, trim: false) _clean(e.cause, trim: true) if e.cause ignore = IGNORE.reject { |path| e.backtrace.first =~ /#{path}/ } skip = false e.backtrace.map! do |line| if trim || ignore.any? { |path| line =~ /#{path}/ } unless skip skip = true '...' end else skip = false line end end e.backtrace.compact! end class_methods do def logger SemanticLogger[name] end def profile_info(name, **kwargs) logger.info "Started #{name}", kwargs.sanitize.inspect logger.measure_info("Completed #{name}") { logger.tagged(name) { yield } } end def profile_debug(name, **kwargs) logger.debug "Started #{name}", kwargs.sanitize.inspect logger.measure_debug("Completed #{name}") { logger.tagged(name) { yield } } end def profile_trace(name, **kwargs) logger.trace "Started #{name}", kwargs.sanitize.inspect logger.measure_trace("Completed #{name}") { logger.tagged(name) { yield } } end end end end
Version data entries
7 entries across 7 versions & 1 rubygems