Class: Bixby::Log::FilteringLayout

Inherits:
Logging::Layouts::Pattern
  • Object
show all
Defined in:
lib/bixby-common/util/log/filtering_layout.rb

Instance Method Summary collapse

Instance Method Details

#filter_ex(ex) ⇒ Array<String>

Filter the exception if a block is available

Parameters:

  • ex (Exception)

Returns:

  • (Array<String>)

    backtrace



14
15
16
17
18
19
20
# File 'lib/bixby-common/util/log/filtering_layout.rb', line 14

def filter_ex(ex)
  if @filter.nil? then
    return ex.backtrace
  end

  return @filter.call(ex)
end

#format_obj(obj) ⇒ String

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.

Parameters:

  • obj (Object)

Returns:

  • (String)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bixby-common/util/log/filtering_layout.rb', line 37

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

#set_filter(&block) {|Exception| ... } ⇒ Object

Set the exception filter

Parameters:

  • block (Block)

Yields:

  • (Exception)

    the exception to filter



26
27
28
# File 'lib/bixby-common/util/log/filtering_layout.rb', line 26

def set_filter(&block)
  @filter = block
end