Class: Philiprehberger::LogFilter::ChainedFilter Private

Inherits:
Filter
  • Object
show all
Defined in:
lib/philiprehberger/log_filter/filter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A filter produced by Filter#chain that pipes events through two source filters in order. Tracks its own stats independently of the inputs. Short-circuits when the first filter drops the event.

Instance Attribute Summary

Attributes inherited from Filter

#rules

Instance Method Summary collapse

Methods inherited from Filter

#chain, #describe_rules, #drop, #drop_field, #drop_if, #explain, #mask_field, #replace, #reset_stats!, #sample, #stats, #tap_each, #truncate

Constructor Details

#initialize(first, second) ⇒ ChainedFilter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ChainedFilter.

Parameters:

  • first (Filter)

    the filter to run first

  • second (Filter)

    the filter to run on first‘s output



435
436
437
438
439
# File 'lib/philiprehberger/log_filter/filter.rb', line 435

def initialize(first, second)
  super()
  @first = first
  @second = second
end

Instance Method Details

#apply(message) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run first.apply then second.apply. If the first returns nil, the second is skipped and nil is returned.

Parameters:

  • message (String)

    the log message to filter

Returns:

  • (String, nil)

    the transformed message, or nil if dropped



446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/philiprehberger/log_filter/filter.rb', line 446

def apply(message)
  intermediate = @first.apply(message)
  if intermediate.nil?
    increment_stat(:dropped)
    return nil
  end

  result = @second.apply(intermediate)
  if result.nil?
    increment_stat(:dropped)
    return nil
  end

  increment_stat(:passed)
  result
end