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, #drop, #drop_field, #drop_if, #mask_field, #replace, #reset_stats!, #sample, #stats

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



238
239
240
241
242
# File 'lib/philiprehberger/log_filter/filter.rb', line 238

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



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/philiprehberger/log_filter/filter.rb', line 249

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