Class: Iudex::Filter::Core::ByFilterLogger

Inherits:
Object
  • Object
show all
Includes:
ByFilterReporter::ReportWriter
Defined in:
lib/iudex-filter/by_filter_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(desc, index) ⇒ ByFilterLogger

Returns a new instance of ByFilterLogger.



29
30
31
32
33
# File 'lib/iudex-filter/by_filter_logger.rb', line 29

def initialize( desc, index )
  @log = RJack::SLF4J[ "iudex.filter.core.ByFilterLogger.#{desc}" ]
  @index = index
  @nlength = index.filters.map { |f| index.name( f ).length }.max
end

Instance Method Details

#dropped(c) ⇒ Object



58
59
60
# File 'lib/iudex-filter/by_filter_logger.rb', line 58

def dropped( c )
  c.rejected + c.failed
end

#fmt(v) ⇒ Object



62
63
64
# File 'lib/iudex-filter/by_filter_logger.rb', line 62

def fmt( v )
  Metric::format( v )
end

#prc(v, t) ⇒ Object



66
67
68
# File 'lib/iudex-filter/by_filter_logger.rb', line 66

def prc( v, t )
  ( t > 0 ) ? v.to_f / t * 100.0 : 0.0
end

#report(total, delta, duration_ns, counters) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/iudex-filter/by_filter_logger.rb', line 35

def report( total, delta, duration_ns, counters )
  out = StringIO.new

  out << "Report total: %s ::\n" % [ fmt( total ) ]
  out << ( "  %-#{@nlength}s %6s %5s %6s %6s" %
           %w{ Filter Accept % Reject Failed } )

  accepted = total
  @index.filters.each do |f|
    c = counters[ f ]
    d = dropped( c )
    if d > 0
      p = prc( -d, accepted )
      accepted -= d
      out << ( "\n  %-#{@nlength}s %6s %4.0f%% %6s %6s" %
               [ @index.name( f ),
                 fmt( accepted ), p,
                 fmt( c.rejected ), fmt( c.failed ) ] )
    end
  end
  @log.info( out.string )
end