Sha256: 884f0f3dd105de57170174d3ed66e7b573f090d717eb4c08351d3bb2723b4aed

Contents?: true

Size: 1.04 KB

Versions: 13

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literals: true

module Lumberjack
  class Formatter
    # Format an exception including the backtrace. You can specify an object that
    # responds to `call` as a backtrace cleaner. The exception backtrace will be
    # passed to this object and the returned array is what will be logged. You can
    # use this to clean out superfluous lines.
    class ExceptionFormatter
      attr_accessor :backtrace_cleaner

      def initialize(backtrace_cleaner = nil)
        self.backtrace_cleaner = backtrace_cleaner
      end

      def call(exception)
        message = "#{exception.class.name}: #{exception.message}"
        trace = exception.backtrace
        if trace
          trace = clean_backtrace(trace)
          message << "#{Lumberjack::LINE_SEPARATOR}  #{trace.join("#{Lumberjack::LINE_SEPARATOR}  ")}"
        end
        message
      end

      private

      def clean_backtrace(trace)
        if trace && backtrace_cleaner
          backtrace_cleaner.call(trace)
        else
          trace
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.35 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/exception_formatter.rb
lumberjack-1.2.8 lib/lumberjack/formatter/exception_formatter.rb