1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-01-31 17:27:13 +00:00

Singularize the Filters module

Since we are using single objects from this namespaces, it is much
more suitable to be named in singular than in plural.
This commit is contained in:
Holger Just 2017-10-21 16:25:15 +02:00
parent aa37d47b8f
commit d721c1fc72
23 changed files with 61 additions and 63 deletions

View File

@ -22,7 +22,7 @@ module Rackstash
# standard library. All logs emitted to the given logger will be emitted
# with the defined severity (`INFO` by default). Since a log event in
# Rackstash can contain multiple concatenanted messages, you should make
# sure to format them properly with {Filters} or a custom encoder if
# sure to format them properly with a {Filter} or a custom encoder if
# required.
#
# While most loggers expect Strings as arguments to their `add` method, some

View File

@ -337,17 +337,16 @@ module Rackstash
#
# Note that the resulting hash still contains an Array of {Message}s in the
# `"message"` field and a `Time` object in the '@timestamp' field. This
# allows the {Flow}'s components (usually the {Filters} or the
# {Flow#encoder}) to reject or adapt some messages based on
# their original attributes, e.g., their severity or timestamp. It is the
# responsibility of the {Flow#encoder} to correctly format the
# `"@timestamp"` field.
# allows the {Flow}'s components (usually a {Filter} or the {Flow#encoder})
# to reject or adapt some messages based on their original attributes, e.g.,
# their severity or timestamp. It is the responsibility of the
# {Flow#encoder} to correctly format the `"@timestamp"` field.
#
# All other fields in the event Hash besides `"message"` and `@timestamp"`
# are either `Hash`, `Array`, frozen `String`, `Integer` or `Float` objects.
# All hashes (including nested hashes) use `String` keys.
#
# @return [Hash] the event expected by the event {Filters}.
# @return [Hash] the event expected by the event {Filter}s.
def to_event
event = fields.to_h
event[FIELD_TAGS] = tags.to_a

View File

@ -5,13 +5,13 @@
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE.txt file for details.
require 'rackstash/filters/clear_color'
require 'rackstash/filters/default_fields'
require 'rackstash/filters/default_tags'
require 'rackstash/filters/rename'
require 'rackstash/filters/replace'
require 'rackstash/filters/skip_event'
require 'rackstash/filters/truncate_message'
require 'rackstash/filter/clear_color'
require 'rackstash/filter/default_fields'
require 'rackstash/filter/default_tags'
require 'rackstash/filter/rename'
require 'rackstash/filter/replace'
require 'rackstash/filter/skip_event'
require 'rackstash/filter/truncate_message'
module Rackstash
# Filters are part of a {Flow} where they can alter the log event before it is
@ -28,16 +28,16 @@ module Rackstash
#
# A filter can be any object responding to `call`, e.g. a Proc or a concrete
# class inside this module.
module Filters
module Filter
# Create a new filter instance from the specified class and the given
# arguments. The class can be given as an actual class or as the name of a
# filter in which case we are resolving it to a class defined inside the
# {Rackstash::Filters} namespace.
# {Rackstash::Filter} namespace.
#
# @param klass [Class, Symbol, String, #call] a description of the class
# from which we are creating a new filter object. When giving a `Class`,
# we are using it as is. When giving a `String` or `Symbol`, we are
# determining the associated class from the {Rackstash::Filters} module
# determining the associated class from the {Rackstash::Filter} module
# and create an instance of that. When giving an object which responds to
# `call` already, we return it unchanged, ignoring any additional passed
# `args`.
@ -66,7 +66,7 @@ module Rackstash
end
# @return [Hash<Symbol => Class>] a Hash with names of filters and their
# respective classes which can be used with {Filters.build} to create a
# respective classes which can be used with {Filter.build} to create a
# new filter object
def self.known
constants.each_with_object({}) do |const, known|

View File

@ -6,7 +6,7 @@
# of the MIT license. See the LICENSE.txt file for details.
module Rackstash
module Filters
module Filter
# Remove all ANSI color codes from the `"message"` field of the given event
# `Hash`.
#

View File

@ -6,7 +6,7 @@
# of the MIT license. See the LICENSE.txt file for details.
module Rackstash
module Filters
module Filter
# The {DefaultFields} filter allows to define fields which should be added
# to an event if they aren't already explicitly set.
#

View File

@ -6,7 +6,7 @@
# of the MIT license. See the LICENSE.txt file for details.
module Rackstash
module Filters
module Filter
# The {DefaultTags} filter allows to define tags which should be added
# to an event if they aren't already explicitly set there. All existing tags
# on the event are retained.

View File

@ -6,7 +6,7 @@
# of the MIT license. See the LICENSE.txt file for details.
module Rackstash
module Filters
module Filter
# Rename one or more fields in the given event.
#
# @example

View File

@ -6,7 +6,7 @@
# of the MIT license. See the LICENSE.txt file for details.
module Rackstash
module Filters
module Filter
# Replace fields in the given event with new values. A new value can be
# specified as either a fixed value or as a `Proc` (or any other object
# responding to `call`). In the latter case, the callable object will be

View File

@ -6,7 +6,7 @@
# of the MIT license. See the LICENSE.txt file for details.
module Rackstash
module Filters
module Filter
# Skip the further processing of the event of the condition is `true`.
#
# This filter is a basic example of how you can write filters which abort

View File

@ -6,7 +6,7 @@
# of the MIT license. See the LICENSE.txt file for details.
module Rackstash
module Filters
module Filter
# The Truncate filter can be used to restrict the size of the emitted
# message. By selectively deleting parts until the message size fits into
# the defined limit, you can ensure that log events are properly handled by

View File

@ -6,7 +6,7 @@
# of the MIT license. See the LICENSE.txt file for details.
module Rackstash
module Filters
module Filter
# Update fields in the given event with new values. A new value can be
# specified as either a fixed value or as a `Proc` (or any other object
# responding to `call`). In the latter case, the callable object will be

View File

@ -11,10 +11,10 @@ module Rackstash
# The FilterChain contains a list of event filters which are used by a {Flow}
# to mutate an event before it is envoded and sent to the adapter for writing.
#
# A filter is any object responding to `call`, e.g. one of the {Filters} or a
# `Proc` object. When running the filters, we call each filter iin turn,
# passing the event. The filter can change the event in any way desired but
# should make sure that it preserves the basic structure of the event:
# A filter is any object responding to `call`, e.g. a {Filter} or a `Proc`
# object. When running the filters, we call each filter in turn, passing the
# event. The filter can change the event in any way desired but should make
# sure that it preserves the basic structure of the event:
#
# * Only use basic objects: `Hash`, `Array`, `String`, `Integer`, `Float`.
# * Hash keys should always be strings
@ -78,8 +78,8 @@ module Rackstash
end
# Adds a new filter at the end of the filter chain. You can either give a
# callable object (e.g. a `Proc` or one of the {Filters}) or specify the
# filter with a given block.
# callable object (e.g. a `Proc` or a {Filter}) or specify the filter with
# a given block.
#
# @param filter_spec (see #build_filter)
# @raise [TypeError] if no suitable filter could be created from
@ -236,8 +236,8 @@ module Rackstash
alias size length
# Prepends a new filter at the beginning of the filter chain. You can either
# give a callable object (e.g. a `Proc` or one of the {Filters}) or specify
# the filter with a given block.
# give a callable object (e.g. a `Proc` or a {Filter}) or specify the filter
# with a given block.
#
# @param filter_spec (see #build_filter)
# @raise [TypeError] if we could not build a filter from the given
@ -296,16 +296,16 @@ module Rackstash
# `#call`), we will directly return it. If you give a `Class` plus any
# optional initializer arguments, we will return a new instance of that
# class. When giving a `String` or `Symbol`, we will resolve it to a
# filter class from the {Rackstash::Filters} module and create a new
# filter class from the {Rackstash::Filter} module and create a new
# instance of that class with the additional arguments given to
# `initialize`.
# @return [#call] a filter instance
def build_filter(filter_spec, &block)
if filter_spec.empty?
return Rackstash::Filters.build(block) if block_given?
return Rackstash::Filter.build(block) if block_given?
raise ArgumentError, 'Need to specify a filter'
else
Rackstash::Filters.build(*filter_spec, &block)
Rackstash::Filter.build(*filter_spec, &block)
end
end
end

View File

@ -7,7 +7,7 @@
require 'rackstash/adapter'
require 'rackstash/encoder'
require 'rackstash/filters'
require 'rackstash/filter'
require 'rackstash/filter_chain'
module Rackstash
@ -19,7 +19,7 @@ module Rackstash
# In order to transform and persist log events, a Flow uses several
# components:
#
# * Any number of {Filters} (zero or more). The filters can change the log
# * Any number of {Filter}s (zero or more). The filters can change the log
# event before it is passed to the adapter by adding, changing, or removing
# fields. The filters also have access to the array of {Message} objects in
# `event["messages"]` which provide the original severity and timestamp of
@ -41,7 +41,7 @@ module Rackstash
# encoder Rackstash::Encoder::JSON.new
#
# # Anonymize IPs in the remote_ip field.
# filter Rackstash::Filters::AnonymizeIPMask.new('remote_ip')
# filter Rackstash::Filter::AnonymizeIPMask.new('remote_ip')
#
# # Add the maximum severity of any message in the event into the
# # severity and severity_label fields.
@ -70,9 +70,8 @@ module Rackstash
# can be wrapped in an adapter. See {Adapter.[]}
# @param encoder [#encode] an encoder, usually one of the {Encoder}s. If
# this is not given, the adapter's default_encoder will be used.
# @param filters [Array<#call>] an array of filters. Can be one of the
# pre-defined {Filters}, a `Proc`, or any other object which responds to
# `call`.
# @param filters [Array<#call>] an array of filters. Can be a pre-defined
# {Filter}, a `Proc`, or any other object which responds to `call`.
# @yieldparam flow [self] if the given block accepts an argument, we yield
# `self` as a parameter, else, the block is directly executed in the
# context of `self`.

View File

@ -14,7 +14,7 @@ module Rackstash
#
# In the end, only the `message` field will be included in the final log
# event. However, the stored meta-data can be useful when filtering or
# changing the messages of a log event using {Filters} later.
# changing the messages of a log event using a {Filter} later.
#
# All `Message` objects and their respective data are immutable after
# initialization.

View File

@ -7,9 +7,9 @@
require 'spec_helper'
require 'rackstash/filters/clear_color'
require 'rackstash/filter/clear_color'
describe Rackstash::Filters::ClearColor do
describe Rackstash::Filter::ClearColor do
let(:filter) { described_class.new }
it 'removes any ANSI color codes from the message' do

View File

@ -7,9 +7,9 @@
require 'spec_helper'
require 'rackstash/filters/default_fields'
require 'rackstash/filter/default_fields'
describe Rackstash::Filters::DefaultFields do
describe Rackstash::Filter::DefaultFields do
let(:event) {
{
'foo' => 'v1',

View File

@ -7,9 +7,9 @@
require 'spec_helper'
require 'rackstash/filters/default_tags'
require 'rackstash/filter/default_tags'
describe Rackstash::Filters::DefaultTags do
describe Rackstash::Filter::DefaultTags do
let(:event) {
{
'key' => 'value'

View File

@ -7,9 +7,9 @@
require 'spec_helper'
require 'rackstash/filters/rename'
require 'rackstash/filter/rename'
describe Rackstash::Filters::Rename do
describe Rackstash::Filter::Rename do
let(:event) {
{
'foo' => 'foo value',

View File

@ -7,9 +7,9 @@
require 'spec_helper'
require 'rackstash/filters/replace'
require 'rackstash/filter/replace'
describe Rackstash::Filters::Replace do
describe Rackstash::Filter::Replace do
let(:event) {
{
'foo' => 'foo value',

View File

@ -7,9 +7,9 @@
require 'spec_helper'
require 'rackstash/filters/skip_event'
require 'rackstash/filter/skip_event'
describe Rackstash::Filters::SkipEvent do
describe Rackstash::Filter::SkipEvent do
describe '#initialize' do
it 'expects a condition' do
expect { described_class.new }.to raise_error TypeError

View File

@ -7,9 +7,9 @@
require 'spec_helper'
require 'rackstash/filters/truncate_message'
require 'rackstash/filter/truncate_message'
describe Rackstash::Filters::TruncateMessage do
describe Rackstash::Filter::TruncateMessage do
let(:max_size) { 36 }
let(:args) { { selectors: [], cut: :bottom } }
let(:filter) { described_class.new(max_size, **args) }

View File

@ -7,9 +7,9 @@
require 'spec_helper'
require 'rackstash/filters/update'
require 'rackstash/filter/update'
describe Rackstash::Filters::Update do
describe Rackstash::Filter::Update do
let(:event) {
{
'foo' => 'foo value',

View File

@ -8,9 +8,9 @@
require 'spec_helper'
require 'securerandom'
require 'rackstash/filters'
require 'rackstash/filter'
describe Rackstash::Filters do
describe Rackstash::Filter do
let(:filter_class) { Class.new }
let(:random) { SecureRandom.hex(6) }
let(:filter_class_name) { :"FilterClass#{random}" }
@ -60,7 +60,7 @@ describe Rackstash::Filters do
end
describe '.known' do
it 'returns a Hash with known Filters' do
it 'returns a Hash with known filters' do
expect(described_class.known).not_to be_empty
expect(described_class.known.keys).to all(