class Logging::Filters::Level

The `Level` filter class provides a simple level-based filtering mechanism that allows events whose log level matches a preconfigured list of values.

Public Class Methods

new(*levels) click to toggle source

Creates a new level filter that will only allow the given levels to propagate through to the logging destination. The levels should be given in symbolic form.

Examples

Logging::Filters::Level.new(:debug, :info)
Calls superclass method Logging::Filter.new
# File lib/logging/filters/level.rb, line 17
def initialize(*levels)
  super()
  levels  = levels.flatten.map {|level| ::Logging::level_num(level)}
  @levels = Set.new(levels)
end

Public Instance Methods

allow(event) click to toggle source

Returns the event if it should be forwarded to the logging appender. Otherwise, `nil` is returned. The log event is allowed if the `event.level` matches one of the levels provided to the filter when it was constructred.

# File lib/logging/filters/level.rb, line 27
def allow(event)
  @levels.include?(event.level) ? event : nil
end