Class: Radar::Filters::KeyFilter
- Inherits:
-
Object
- Object
- Radar::Filters::KeyFilter
- Defined in:
- lib/radar/filters/key_filter.rb
Overview
Filters the event data by filtering out a given key which can exist anywhere in the data hash. For example, given the following hash:
{ :request => { :password => "foo" },
:rack_env => { :params => { :password => "foo" } } }
If the KeyFilter was configured like so:
app.filters.use :key, :key => :password
Then the data hash would turn into:
{ :request => { :password => "[FILTERED]" },
:rack_env => { :params => { :password => "[FILTERED]" } } }
Options
:key
- A single element or array of elements which represent the keys to filter out of the event hash.:filter_text
- The text which replaces keys which are caught by the filter. This defaults to "[FILTERED]"
Instance Attribute Summary collapse
-
#filter_text ⇒ Object
Returns the value of attribute filter_text.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #filter(data) ⇒ Object
-
#initialize(opts = nil) ⇒ KeyFilter
constructor
A new instance of KeyFilter.
Constructor Details
#initialize(opts = nil) ⇒ KeyFilter
Returns a new instance of KeyFilter.
30 31 32 33 34 35 36 |
# File 'lib/radar/filters/key_filter.rb', line 30 def initialize(opts=nil) (opts || {}).each do |k,v| send("#{k}=", v) end @filter_text ||= "[FILTERED]" end |
Instance Attribute Details
#filter_text ⇒ Object
Returns the value of attribute filter_text.
28 29 30 |
# File 'lib/radar/filters/key_filter.rb', line 28 def filter_text @filter_text end |
#key ⇒ Object
Returns the value of attribute key.
27 28 29 |
# File 'lib/radar/filters/key_filter.rb', line 27 def key @key end |
Instance Method Details
#filter(data) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/radar/filters/key_filter.rb', line 38 def filter(data) # Convert the keys to strings, since we always compare against strings filter_keys = [key].flatten.collect { |k| k.to_s } data.each do |k,v| if filter_keys.include?(k.to_s) data[k] = filter_text elsif v.is_a?(Hash) filter(v) end end data end |