Sha256: 3dcdad4614314b75ccfa0427b357a0c817d0564c4b953aa35e925c293abbc5ff

Contents?: true

Size: 1.43 KB

Versions: 13

Compression:

Stored size: 1.43 KB

Contents

module Bixby
  module Log

    class FilteringLayout < Logging::Layouts::Pattern

      # Filter the exception if a block is available
      #
      # @param [Exception] ex
      #
      # @return [Array<String>] backtrace
      def filter_ex(ex)
        if @filter.nil? then
          return ex.backtrace
        end

        return @filter.call(ex)
      end

      # Set the exception filter
      #
      # @param [Block] block
      # @yield [Exception] the exception to filter
      def set_filter(&block)
        @filter = block
      end

      # Return a string representation of the given object. Depending upon
      # the configuration of the logger system the format will be an +inspect+
      # based representation or a +yaml+ based representation.
      #
      # @param [Object] obj
      #
      # @return [String]
      def format_obj( obj )
        case obj
        when String; obj
        when Exception
          str = "<#{obj.class.name}> #{obj.message}"
          if @backtrace && !obj.backtrace.nil?
            str << "\n\t" << filter_ex(obj).join("\n\t")
          end
          str
        when nil; "<#{obj.class.name}> nil"
        else
          str = "<#{obj.class.name}> "
          str << case @obj_format
                 when :inspect; obj.inspect
                 when :yaml; try_yaml(obj)
                 when :json; try_json(obj)
                 else obj.to_s end
          str
        end
      end

    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bixby-common-0.4.6 lib/bixby-common/util/log/filtering_layout.rb
bixby-common-0.4.5 lib/bixby-common/util/log/filtering_layout.rb
bixby-common-0.4.4 lib/bixby-common/util/log/filtering_layout.rb
bixby-common-0.4.3 lib/bixby-common/util/log/filtering_layout.rb
bixby-common-0.4.2 lib/bixby-common/util/log/filtering_layout.rb
bixby-common-0.4.1 lib/bixby-common/util/log/filtering_layout.rb
bixby-common-0.4.0 lib/bixby-common/util/log/filtering_layout.rb
bixby-common-0.3.16 lib/bixby-common/util/log/filtering_layout.rb
bixby-common-0.3.15 lib/bixby_common/util/log/filtering_layout.rb
bixby-common-0.3.14 lib/bixby_common/util/log/filtering_layout.rb
bixby-common-0.3.13 lib/bixby_common/util/log/filtering_layout.rb
bixby-common-0.3.12 lib/bixby_common/util/log/filtering_layout.rb
bixby-common-0.3.11 lib/bixby_common/util/log/filtering_layout.rb