mirror of
https://github.com/meineerde/rackstash.git
synced 2026-01-31 17:27:13 +00:00
Singularize the Adapter and Encoder modules
Since we are using single objects from these namespaces, they are much more suitable to be named in singular than in plural.
This commit is contained in:
parent
e857cdb9f1
commit
aa37d47b8f
@ -136,7 +136,7 @@ module Rackstash
|
||||
FIELD_STATUS = 'status'.freeze
|
||||
|
||||
# Returns a {Flow} which is used by the normal logger {Flow}s to write details
|
||||
# about any unexpected errors during interaction with their {Adapters}.
|
||||
# about any unexpected errors during interaction with their {Adapter}s.
|
||||
#
|
||||
# By default, this Flow logs JSON-formatted messages to `STDERR`
|
||||
#
|
||||
@ -146,7 +146,7 @@ module Rackstash
|
||||
end
|
||||
|
||||
# Set a {Flow} which is used bythe normal logger {Flow}s to write details
|
||||
# of any unexpected errors during interaction with their {Adapters}.
|
||||
# of any unexpected errors during interaction with their {Adapter}s.
|
||||
#
|
||||
# You can set a different `error_flow` for each {Flow} if required. You can
|
||||
# also change this flow to match your desired fallback format and log adapter.
|
||||
@ -156,7 +156,7 @@ module Rackstash
|
||||
# external issues, it is usually desireable to chose a local and mostly
|
||||
# relibable log target.
|
||||
#
|
||||
# @param flow [Flow, Adapters::Adapter, Object] a single {Flow} or an object
|
||||
# @param flow [Flow, Adapter::Adapter, Object] a single {Flow} or an object
|
||||
# which can be used as a {Flow}'s adapter. See {Flow#initialize}.
|
||||
# @return [Rackstash::Flow] the given `flow`
|
||||
def self.error_flow=(flow)
|
||||
@ -167,8 +167,8 @@ end
|
||||
|
||||
require 'rackstash/logger'
|
||||
|
||||
require 'rackstash/adapters/callable'
|
||||
require 'rackstash/adapters/file'
|
||||
require 'rackstash/adapters/logger'
|
||||
require 'rackstash/adapters/io'
|
||||
require 'rackstash/adapters/null'
|
||||
require 'rackstash/adapter/callable'
|
||||
require 'rackstash/adapter/file'
|
||||
require 'rackstash/adapter/logger'
|
||||
require 'rackstash/adapter/io'
|
||||
require 'rackstash/adapter/null'
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
require 'uri'
|
||||
|
||||
module Rackstash
|
||||
module Adapters
|
||||
module Adapter
|
||||
class << self
|
||||
# Register a concrete adapter class which can be instanciated with a
|
||||
# certain log device (e.g. a file name, an IO object, a URL specifying a
|
||||
@ -41,12 +41,12 @@ module Rackstash
|
||||
# @param matchers [Array<String, Symbol, #===>] a list of specifications
|
||||
# for log devices the `adapter_class` can forward logs to.
|
||||
# @raise [TypeError] if the passed adapter_class is not a class
|
||||
# inheriting from {Adapters::Adapter}
|
||||
# inheriting from {Adapter::Adapter}
|
||||
# @return [Class] the `adapter_class`
|
||||
def register(adapter_class, *matchers)
|
||||
unless adapter_class.is_a?(Class) && adapter_class < Adapters::Adapter
|
||||
unless adapter_class.is_a?(Class) && adapter_class < Rackstash::Adapter::Adapter
|
||||
raise TypeError, 'adapter_class must be a class and inherit from ' \
|
||||
'Rackstash::Adapters::Adapter'
|
||||
'Rackstash::Adapter::Adapter'
|
||||
end
|
||||
|
||||
matchers.flatten.each do |matcher|
|
||||
@ -85,14 +85,14 @@ module Rackstash
|
||||
#
|
||||
# if no suitable adapter can be found, we raise an `ArgumentError`.
|
||||
#
|
||||
# @param device [Adapters::Adapter, Object] a log device which should be
|
||||
# @param device [Adapter::Adapter, Object] a log device which should be
|
||||
# wrapped in an {Adapter}. If it is already an adapter, the `device` is
|
||||
# returned unchanged.
|
||||
# @raise [ArgumentError] if no suitable adapter could be found for the
|
||||
# provided `device`
|
||||
# @return [Adapters::Adapter] the resolved adapter instance
|
||||
# @return [Adapter::Adapter] the resolved adapter instance
|
||||
def [](device)
|
||||
return device if device.is_a?(Adapters::Adapter)
|
||||
return device if device.is_a?(Rackstash::Adapter::Adapter)
|
||||
|
||||
adapter = adapter_by_uri(device)
|
||||
adapter ||= adapter_by_type(device)
|
||||
@ -5,18 +5,18 @@
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/adapters'
|
||||
require 'rackstash/encoders/json'
|
||||
require 'rackstash/adapter'
|
||||
require 'rackstash/encoder/json'
|
||||
|
||||
module Rackstash
|
||||
module Adapters
|
||||
module Adapter
|
||||
# The Adapter wraps a raw external log device like a file, an IO object like
|
||||
# `STDOUT`, the system's syslog or even the connection to a TCP server with
|
||||
# a common interface. At the end of a {Flow}, it is responsible to finally
|
||||
# store the filtered and encoded log event.
|
||||
#
|
||||
# Each concrete adapter can register itself so that it can be used to wrap
|
||||
# any compatible log device with {Rackstash::Adapters.[]}.
|
||||
# any compatible log device with {Rackstash::Adapter.[]}.
|
||||
#
|
||||
# @abstract Subclasses need to override at least {#write_single} to
|
||||
# implement a concrete log adapter.
|
||||
@ -31,25 +31,27 @@ module Rackstash
|
||||
# @return [self]
|
||||
# @see Adapter.register
|
||||
def self.register_for(*matchers)
|
||||
Rackstash::Adapters.register(self, *matchers)
|
||||
Rackstash::Adapter.register(self, *matchers)
|
||||
end
|
||||
|
||||
# Create a new adapter instance.
|
||||
#
|
||||
# Usually, this method is overwritten by child classes to accept a
|
||||
# suitable log device which will be used to write log lines to. When
|
||||
# registering the adapter class, {Rackstash::Adapters.[]} will call
|
||||
# registering the adapter class, {Rackstash::Adapter.[]} will call
|
||||
# {initialize} with a single argument: the log device.
|
||||
def initialize(*)
|
||||
end
|
||||
|
||||
# Return a new Encoder instance which can be used with the concrete adapter
|
||||
# If no explicit encoder is defined in a {Flow}, this encoder will be used
|
||||
# there
|
||||
# By default, we use a {Rackstash::Encoder::JSON} encoder to encode the
|
||||
# events for the adapter.
|
||||
#
|
||||
# @return [#call] an encoder
|
||||
# If no explicit encoder is defined in a {Flow}, this encoder will be used
|
||||
# there.
|
||||
#
|
||||
# @return [Rackstash::Encoder::JSON] a new JSON encoder
|
||||
def default_encoder
|
||||
Rackstash::Encoders::JSON.new
|
||||
Rackstash::Encoder::JSON.new
|
||||
end
|
||||
|
||||
# Close the underlying log device if supported by it.
|
||||
@ -5,11 +5,11 @@
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/adapters/adapter'
|
||||
require 'rackstash/encoders/hash'
|
||||
require 'rackstash/adapter/adapter'
|
||||
require 'rackstash/encoder/hash'
|
||||
|
||||
module Rackstash
|
||||
module Adapters
|
||||
module Adapter
|
||||
# This adapter calls a user-provided "callable", i.e., a `Proc` or block for
|
||||
# each written log line. This allows users to custom handle the logs without
|
||||
# having to write a full custom adapter class.
|
||||
@ -24,7 +24,7 @@ module Rackstash
|
||||
#
|
||||
# To create an adapter instance, you can use this example:
|
||||
#
|
||||
# Rackstash::Adapters::Callable.new do |log|
|
||||
# Rackstash::Adapter::Callable.new do |log|
|
||||
# # handle the log as required
|
||||
# end
|
||||
class Callable < Adapter
|
||||
@ -46,15 +46,15 @@ module Rackstash
|
||||
end
|
||||
end
|
||||
|
||||
# By default, we use an {Rackstash::Encoders::Hash} to encode the events.
|
||||
# This ensures that all of the data in the logged event is passed through
|
||||
# to the callable by default.
|
||||
# By default, we use a {Rackstash::Encoder::Hash} encoder to encode the
|
||||
# events for the adapter. This ensures that all of the data in the logged
|
||||
# event is passed through to the callable by default.
|
||||
#
|
||||
# You can define a custom encoder in the responsible {Flow}.
|
||||
#
|
||||
# @return [Rackstash::Encoders::Hash] a new Hash encoder
|
||||
# @return [Rackstash::Encoder::Hash] a new Hash encoder
|
||||
def default_encoder
|
||||
Rackstash::Encoders::Hash.new
|
||||
Rackstash::Encoder::Hash.new
|
||||
end
|
||||
|
||||
# Write a single log line by calling the defined `callable` given in
|
||||
@ -9,10 +9,10 @@ require 'fileutils'
|
||||
require 'pathname'
|
||||
require 'thread'
|
||||
|
||||
require 'rackstash/adapters/adapter'
|
||||
require 'rackstash/adapter/adapter'
|
||||
|
||||
module Rackstash
|
||||
module Adapters
|
||||
module Adapter
|
||||
# This log adapter allows to write logs to a file acessible on the local
|
||||
# filesystem. We assume filesystem semantics of the usual local filesystems
|
||||
# used on Linux, macOS, BSDs, or Windows. Here, we can ensure that even
|
||||
@ -33,7 +33,7 @@ module Rackstash
|
||||
#
|
||||
# Assuming you are creating the log adapter like this
|
||||
#
|
||||
# Rackstash::Adapters::File.new('/var/log/rackstash/my_app.log')
|
||||
# Rackstash::Adapter::File.new('/var/log/rackstash/my_app.log')
|
||||
#
|
||||
# you can rotate the file with a config for the standard
|
||||
# [logrotate](https://github.com/logrotate/logrotate) utility similar to
|
||||
@ -158,7 +158,7 @@ module Rackstash
|
||||
FileUtils.mkdir_p ::File.dirname(@filename)
|
||||
end
|
||||
|
||||
file = ::File.open(
|
||||
file = ::File.new(
|
||||
filename,
|
||||
::File::WRONLY | ::File::APPEND | ::File::CREAT,
|
||||
external_encoding: Encoding::UTF_8
|
||||
@ -7,10 +7,10 @@
|
||||
|
||||
require 'thread'
|
||||
|
||||
require 'rackstash/adapters/adapter'
|
||||
require 'rackstash/adapter/adapter'
|
||||
|
||||
module Rackstash
|
||||
module Adapters
|
||||
module Adapter
|
||||
# This adapter allows to write logs to an existing `IO` object, e.g.,
|
||||
# `STDOUT`, an open file, a `StringIO` object, ...
|
||||
#
|
||||
@ -29,11 +29,11 @@ module Rackstash
|
||||
# when writing large log lines (typically > 4 KB). If you are using such a
|
||||
# deployment model and expect large log lines, you should consider using a
|
||||
# different adapter to ensure consistent logs. Suitable adapters for this
|
||||
# use-case include {Rackstash::Adapters::File} or
|
||||
# {Rackstash::Adapters::TCP}.
|
||||
# use-case include {Rackstash::Adapter::File} or
|
||||
# {Rackstash::Adapter::TCP}.
|
||||
class IO < Adapter
|
||||
# This module is by default included into all objects passed to
|
||||
# {Adapters::IO#initialize}. It allows to synchronize all write accesses
|
||||
# {Adapter::IO#initialize}. It allows to synchronize all write accesses
|
||||
# against this object, even when writing to the same object from multiple
|
||||
# adapters concurrently.
|
||||
#
|
||||
@ -7,10 +7,10 @@
|
||||
|
||||
require 'logger'
|
||||
|
||||
require 'rackstash/adapters/adapter'
|
||||
require 'rackstash/adapter/adapter'
|
||||
|
||||
module Rackstash
|
||||
module Adapters
|
||||
module Adapter
|
||||
# The Logger adapter can be used to write formatted logs to an existing
|
||||
# logger. This is especially useful with libraries exposing a
|
||||
# logger-compatible interface for an external protocol. Example of such
|
||||
@ -5,11 +5,11 @@
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/adapters/adapter'
|
||||
require 'rackstash/encoders/raw'
|
||||
require 'rackstash/adapter/adapter'
|
||||
require 'rackstash/encoder/raw'
|
||||
|
||||
module Rackstash
|
||||
module Adapters
|
||||
module Adapter
|
||||
# This adapter swallows all logs sent to it without writing them anywhere.
|
||||
#
|
||||
# It is probably not very useful for production use but can be used to test
|
||||
@ -22,13 +22,13 @@ module Rackstash
|
||||
def initialize(*)
|
||||
end
|
||||
|
||||
# By default, we use a {Rackstash::Encoders::Raw} encoder to encode the
|
||||
# By default, we use a {Rackstash::Encoder::Raw} encoder to encode the
|
||||
# events. Since we are ignoreing them anyway, there is no need for fancy
|
||||
# formatting here.
|
||||
#
|
||||
# @return [Rackstash::Encoders::Raw] a new Raw encoder
|
||||
# @return [Rackstash::Encoder::Raw] a new Raw encoder
|
||||
def default_encoder
|
||||
Rackstash::Encoders::Raw.new
|
||||
Rackstash::Encoder::Raw.new
|
||||
end
|
||||
|
||||
# Swallow a log event. It is not written anywhere.
|
||||
13
lib/rackstash/encoder.rb
Normal file
13
lib/rackstash/encoder.rb
Normal file
@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Copyright 2017 Holger Just
|
||||
#
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/encoder/hash'
|
||||
require 'rackstash/encoder/json'
|
||||
require 'rackstash/encoder/lograge'
|
||||
require 'rackstash/encoder/logstash'
|
||||
require 'rackstash/encoder/message'
|
||||
require 'rackstash/encoder/raw'
|
||||
@ -5,17 +5,17 @@
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/encoders/helpers/message'
|
||||
require 'rackstash/encoders/helpers/timestamp'
|
||||
require 'rackstash/encoder/helper/message'
|
||||
require 'rackstash/encoder/helper/timestamp'
|
||||
|
||||
module Rackstash
|
||||
module Encoders
|
||||
module Encoder
|
||||
# The Hash encoder formats the log event as a raw `Hash` containing all data
|
||||
# exposed by the buffer. This can be used by special log targets which are
|
||||
# designed to handle hashes as opposed to formatted strings.
|
||||
class Hash
|
||||
include Rackstash::Encoders::Helpers::Message
|
||||
include Rackstash::Encoders::Helpers::Timestamp
|
||||
include Rackstash::Encoder::Helper::Message
|
||||
include Rackstash::Encoder::Helper::Timestamp
|
||||
|
||||
# @param event [Hash] a log event as produced by the {Flow}
|
||||
# @return [Hash] the normalized event
|
||||
@ -6,10 +6,10 @@
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
module Rackstash
|
||||
module Encoders
|
||||
module Helpers
|
||||
# Some useful helper methods for {Encoders} which help in normalizing and
|
||||
# handling the message list in the event Hash.
|
||||
module Encoder
|
||||
module Helper
|
||||
# Some useful helper methods for {Rackstash::Encoder}s which help in
|
||||
# normalizing and handling the message list in the event Hash.
|
||||
module Message
|
||||
private
|
||||
|
||||
@ -9,11 +9,11 @@ require 'date'
|
||||
require 'time'
|
||||
|
||||
module Rackstash
|
||||
module Encoders
|
||||
module Helpers
|
||||
# Some useful helper methods for {Encoders} which help in normalizing and
|
||||
# handling timestamps in the event Hash, especially the {FIELD_TIMESTAMP}
|
||||
# field.
|
||||
module Encoder
|
||||
module Helper
|
||||
# Some useful helper methods for {Rackstash::Encoder}s which help in
|
||||
# normalizing and handling timestamps in the event Hash, especially the
|
||||
# {FIELD_TIMESTAMP} field.
|
||||
module Timestamp
|
||||
private
|
||||
|
||||
@ -7,18 +7,18 @@
|
||||
|
||||
require 'json'
|
||||
|
||||
require 'rackstash/encoders/helpers/message'
|
||||
require 'rackstash/encoders/helpers/timestamp'
|
||||
require 'rackstash/encoder/helper/message'
|
||||
require 'rackstash/encoder/helper/timestamp'
|
||||
|
||||
module Rackstash
|
||||
module Encoders
|
||||
module Encoder
|
||||
# The JSON encoder formats the log event as a single-line JSON string. The
|
||||
# resulting JSON string contains all data exposed by the buffer.
|
||||
#
|
||||
# Most {Adapters} default to use this codec.
|
||||
# Most adapters default to use this encoder.
|
||||
class JSON
|
||||
include Rackstash::Encoders::Helpers::Message
|
||||
include Rackstash::Encoders::Helpers::Timestamp
|
||||
include Rackstash::Encoder::Helper::Message
|
||||
include Rackstash::Encoder::Helper::Timestamp
|
||||
|
||||
# @param event [Hash] a log event as produced by the {Flow}
|
||||
# @return [String] the event as a single-line JSON string
|
||||
@ -5,10 +5,10 @@
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/encoders/helpers/timestamp'
|
||||
require 'rackstash/encoder/helper/timestamp'
|
||||
|
||||
module Rackstash
|
||||
module Encoders
|
||||
module Encoder
|
||||
# The Lograge encoder formats the log event in the original key-value format
|
||||
# of the [lograge gem](https://github.com/roidrage/lograge).
|
||||
#
|
||||
@ -62,7 +62,7 @@ module Rackstash
|
||||
# timestamp=2017-04-18T23:21:58.000000Z error='RuntimeError: Something bad happened'
|
||||
#
|
||||
class Lograge
|
||||
include Rackstash::Encoders::Helpers::Timestamp
|
||||
include Rackstash::Encoder::Helper::Timestamp
|
||||
|
||||
SKIP = [
|
||||
FIELD_MESSAGE,
|
||||
@ -5,10 +5,10 @@
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/encoders/json'
|
||||
require 'rackstash/encoder/json'
|
||||
|
||||
module Rackstash
|
||||
module Encoders
|
||||
module Encoder
|
||||
# The Logstash encoder formats the log event as a single-line JSON string in
|
||||
# the JSON format native to Logstash. You can thus ship your logs directly
|
||||
# to Logstash without further processing by using Logstash's
|
||||
@ -5,10 +5,10 @@
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/encoders/helpers/message'
|
||||
require 'rackstash/encoder/helper/message'
|
||||
|
||||
module Rackstash
|
||||
module Encoders
|
||||
module Encoder
|
||||
# The Message encoder only returns the formatted message of log event. All
|
||||
# other fields and tags are ignored. This encoder is useful in environments
|
||||
# where the added fields are not required, mostly during development where
|
||||
@ -18,7 +18,7 @@ module Rackstash
|
||||
# values from the event and prefix them to each line in the message if the
|
||||
# current event contains a value at the given field names.
|
||||
#
|
||||
# encoder = Rackstash::Encoders::Message.new(tagged: ['tags', 'remote_ip'])
|
||||
# encoder = Rackstash::Encoder::Message.new(tagged: ['tags', 'remote_ip'])
|
||||
#
|
||||
# event = {
|
||||
# 'remote_ip' => '127.0.0.1',
|
||||
@ -29,7 +29,7 @@ module Rackstash
|
||||
# encoder.encode(event)
|
||||
# # Logs "[foo,123] [127.0.0.1] Hello\n[foo,123] [127.0.0.1] World\n"
|
||||
class Message
|
||||
include Rackstash::Encoders::Helpers::Message
|
||||
include Rackstash::Encoder::Helper::Message
|
||||
|
||||
# @param tagged [Array<#to_s>] An array of field names whose values are
|
||||
# added in front of each message line on encode
|
||||
@ -6,13 +6,13 @@
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
module Rackstash
|
||||
module Encoders
|
||||
module Encoder
|
||||
# The Raw encoder passes along the raw unformatted event hash. It still
|
||||
# contains an `Array` of {Message} objects in the `"message"` key and a
|
||||
# `Time` object in the `"@timestamp"` key.
|
||||
#
|
||||
# When expecting a Hash in an adapter, usually it's more useful to use the
|
||||
# {Rackstash::Encoders::Hash} encoder instead.
|
||||
# {Rackstash::Encoder::Hash} encoder instead.
|
||||
class Raw
|
||||
# @param event [Hash] a log event as produced by the {Flow}
|
||||
# @return [Hash] the passed `event`
|
||||
@ -1,13 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Copyright 2017 Holger Just
|
||||
#
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/encoders/hash'
|
||||
require 'rackstash/encoders/json'
|
||||
require 'rackstash/encoders/lograge'
|
||||
require 'rackstash/encoders/logstash'
|
||||
require 'rackstash/encoders/message'
|
||||
require 'rackstash/encoders/raw'
|
||||
@ -5,8 +5,8 @@
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/adapters'
|
||||
require 'rackstash/encoders'
|
||||
require 'rackstash/adapter'
|
||||
require 'rackstash/encoder'
|
||||
require 'rackstash/filters'
|
||||
require 'rackstash/filter_chain'
|
||||
|
||||
@ -28,17 +28,17 @@ module Rackstash
|
||||
# format suitable for the final log adapter. Most of the time, the encoder
|
||||
# generates a String but can also produce other formats. Be sure to chose
|
||||
# an encoder which matches the adapter's expectations. Usually, this is one
|
||||
# of the {Encoders}.
|
||||
# of the {Encoder}s.
|
||||
# * And finally the log `Adapter` which is responsible to send the encoded log
|
||||
# event to an external log target, e.g. a file or an external log receiver.
|
||||
# When setting up the flow, you can either provide an existing adapter
|
||||
# object or provide an object which can be wrapped in an adapter. See
|
||||
# {Adapters} for a list of pre-defined log adapters.
|
||||
# {Adapter} for a list of pre-defined log adapters.
|
||||
#
|
||||
# You can build a Flow using a simple DSL:
|
||||
#
|
||||
# flow = Rackstash::Flow.new(STDOUT) do
|
||||
# encoder Rackstash::Encoders::JSON.new
|
||||
# encoder Rackstash::Encoder::JSON.new
|
||||
#
|
||||
# # Anonymize IPs in the remote_ip field.
|
||||
# filter Rackstash::Filters::AnonymizeIPMask.new('remote_ip')
|
||||
@ -60,15 +60,15 @@ module Rackstash
|
||||
# The event which eventually gets written to the flow is created from a Buffer
|
||||
# with {Buffer#to_event}.
|
||||
class Flow
|
||||
# @return [Adapters::Adapter] the log adapter
|
||||
# @return [Adapter::Adapter] the log adapter
|
||||
attr_reader :adapter
|
||||
|
||||
# @return [FilterChain] the mutable filter chain.
|
||||
attr_reader :filter_chain
|
||||
|
||||
# @param adapter [Adapters::Adapter, Object] an adapter or an object which
|
||||
# can be wrapped in an adapter. See {Adapters.[]}
|
||||
# @param encoder [#encode] an encoder, usually one of the {Encoders}. If
|
||||
# @param adapter [Adapter::Adapter, Object] an adapter or an object which
|
||||
# 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
|
||||
@ -77,7 +77,7 @@ module Rackstash
|
||||
# `self` as a parameter, else, the block is directly executed in the
|
||||
# context of `self`.
|
||||
def initialize(adapter, encoder: nil, filters: [], error_flow: nil, &block)
|
||||
@adapter = Rackstash::Adapters[adapter]
|
||||
@adapter = Rackstash::Adapter[adapter]
|
||||
self.encoder = encoder || @adapter.default_encoder
|
||||
@filter_chain = Rackstash::FilterChain.new(filters)
|
||||
self.error_flow = error_flow
|
||||
|
||||
@ -14,7 +14,7 @@ module Rackstash
|
||||
# used to write a single log event of a {Buffer} to multiple flows. Each
|
||||
# {Logger} object has an associated Flows object to define the logger's flows.
|
||||
class Flows
|
||||
# @param flows [::Array<Flow, Adapters::Adapter, Object>] the {Flow} objects
|
||||
# @param flows [::Array<Flow, Adapter::Adapter, Object>] the {Flow} objects
|
||||
# which should be part of the list. If any of the arguments is not a
|
||||
# {Flow} already, we assume it is an adapter and create a new {Flow} for
|
||||
# it.
|
||||
@ -28,7 +28,7 @@ module Rackstash
|
||||
|
||||
# Add a new flow at the end of the list.
|
||||
#
|
||||
# @param flow [Flow, Adapters::Adapter, Object] The flow to add to the end
|
||||
# @param flow [Flow, Adapter::Adapter, Object] The flow to add to the end
|
||||
# of the list. If the argument is not a {Flow}, we assume it is an adapter
|
||||
# and create a new {Flow} with it.
|
||||
# @return [self]
|
||||
@ -51,7 +51,7 @@ module Rackstash
|
||||
# is an adapter and create a new {Flow} for it.
|
||||
#
|
||||
# @param index [Integer] the index in the list where we set the flow
|
||||
# @param flow [Flow, Adapters::Adapter, Object] The flow to add at `index`.
|
||||
# @param flow [Flow, Adapter::Adapter, Object] The flow to add at `index`.
|
||||
# If the argument is not a {Flow}, we assume it is an adapter and create
|
||||
# a new {Flow} with it.
|
||||
# @return [void]
|
||||
|
||||
@ -59,11 +59,11 @@ module Rackstash
|
||||
#
|
||||
# * A {Rackstash::Flow} object. For the most control over the flow, you can
|
||||
# create the {Flow} object on your own and pass it here
|
||||
# * A {Rackstash::Adapters::Adapter}. When passing an adapter, we will
|
||||
# * A {Rackstash::Adapter::Adapter}. When passing an adapter, we will
|
||||
# create a new {Flow} from this adapter, using its default encoder and
|
||||
# without any defined filters.
|
||||
# * An log device from which we can create an adapter. In this case, we
|
||||
# first attempt to build an adapter from it using {Rackstash::Adapters.[]}.
|
||||
# first attempt to build an adapter from it using {Rackstash::Adapter.[]}.
|
||||
# After that, we use it to create a {Flow} as above.
|
||||
#
|
||||
# When passing a block to this initializer, we will yield the last created
|
||||
@ -74,16 +74,16 @@ module Rackstash
|
||||
# The following three example to create a custom Logger are thus equivalent:
|
||||
#
|
||||
# logger = Rackstash::Logger.new(STDOUT) do
|
||||
# encoder Rackstash::Encoders::Message.new
|
||||
# encoder Rackstash::Encoder::Message.new
|
||||
# end
|
||||
#
|
||||
# logger = Rackstash::Logger.new(Rackstash::Adapters::IO.new(STDOUT)) do
|
||||
# encoder Rackstash::Encoders::Message.new
|
||||
# logger = Rackstash::Logger.new(Rackstash::Adapter::IO.new(STDOUT)) do
|
||||
# encoder Rackstash::Encoder::Message.new
|
||||
# end
|
||||
#
|
||||
# adapter = Rackstash::Adapters::IO.new(STDOUT)
|
||||
# adapter = Rackstash::Adapter::IO.new(STDOUT)
|
||||
# flow = Rackstash::Flows.new(adapter) do
|
||||
# encoder Rackstash::Encoders::Message.new
|
||||
# encoder Rackstash::Encoder::Message.new
|
||||
# end
|
||||
# logger = Rackstash::Logger.new(flow)
|
||||
#
|
||||
@ -92,7 +92,7 @@ module Rackstash
|
||||
#
|
||||
# logger = Rackstash::Logger.new(STDOUT)
|
||||
#
|
||||
# @param flows [Array<Flow, Object>, Flow, Adapters::Adapter, Object]
|
||||
# @param flows [Array<Flow, Object>, Flow, Adapter::Adapter, Object]
|
||||
# an array of {Flow}s or a single {Flow}, respectivly object which can be
|
||||
# used as a {Flow}'s adapter. See {Flow#initialize}.
|
||||
# @param level [Integer] a numeric log level. Normally you'd use one of the
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/adapters/adapter'
|
||||
require 'rackstash/adapter/adapter'
|
||||
|
||||
describe Rackstash::Adapters::Adapter do
|
||||
describe Rackstash::Adapter::Adapter do
|
||||
let(:adapter) { described_class.new }
|
||||
|
||||
describe '#initialize' do
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/adapters/callable'
|
||||
require 'rackstash/adapter/callable'
|
||||
|
||||
describe Rackstash::Adapters::Callable do
|
||||
describe Rackstash::Adapter::Callable do
|
||||
let(:callable) { ->(log) { log } }
|
||||
let(:adapter) { described_class.new(callable) }
|
||||
|
||||
@ -33,7 +33,7 @@ describe Rackstash::Adapters::Callable do
|
||||
|
||||
describe '.default_encoder' do
|
||||
it 'returns a Hash encoder' do
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoders::Hash
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoder::Hash
|
||||
end
|
||||
end
|
||||
|
||||
@ -9,9 +9,9 @@ require 'spec_helper'
|
||||
require 'tempfile'
|
||||
require 'tmpdir'
|
||||
|
||||
require 'rackstash/adapters/file'
|
||||
require 'rackstash/adapter/file'
|
||||
|
||||
describe Rackstash::Adapters::File do
|
||||
describe Rackstash::Adapter::File do
|
||||
let!(:logfile) { Tempfile.new('') }
|
||||
|
||||
let(:adapter_args) { {} }
|
||||
@ -56,7 +56,7 @@ describe Rackstash::Adapters::File do
|
||||
|
||||
describe '.default_encoder' do
|
||||
it 'returns a JSON encoder' do
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoders::JSON
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoder::JSON
|
||||
end
|
||||
end
|
||||
|
||||
@ -9,9 +9,9 @@ require 'spec_helper'
|
||||
require 'stringio'
|
||||
require 'tempfile'
|
||||
|
||||
require 'rackstash/adapters/io'
|
||||
require 'rackstash/adapter/io'
|
||||
|
||||
describe Rackstash::Adapters::IO do
|
||||
describe Rackstash::Adapter::IO do
|
||||
let(:io) { StringIO.new }
|
||||
let(:adapter) { described_class.new(io) }
|
||||
|
||||
@ -31,7 +31,7 @@ describe Rackstash::Adapters::IO do
|
||||
|
||||
describe '.default_encoder' do
|
||||
it 'returns a JSON encoder' do
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoders::JSON
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoder::JSON
|
||||
end
|
||||
end
|
||||
|
||||
@ -8,9 +8,9 @@
|
||||
require 'spec_helper'
|
||||
require 'stringio'
|
||||
|
||||
require 'rackstash/adapters/logger'
|
||||
require 'rackstash/adapter/logger'
|
||||
|
||||
describe Rackstash::Adapters::Logger do
|
||||
describe Rackstash::Adapter::Logger do
|
||||
let(:bucket) {
|
||||
Struct.new(:lines) do
|
||||
def initialize(*args)
|
||||
@ -66,7 +66,7 @@ describe Rackstash::Adapters::Logger do
|
||||
|
||||
describe '.default_encoder' do
|
||||
it 'returns a JSON encoder' do
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoders::JSON
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoder::JSON
|
||||
end
|
||||
end
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/adapters/null'
|
||||
require 'rackstash/adapter/null'
|
||||
|
||||
describe Rackstash::Adapters::Null do
|
||||
describe Rackstash::Adapter::Null do
|
||||
let(:adapter) { described_class.new }
|
||||
|
||||
describe '#initialize' do
|
||||
@ -21,7 +21,7 @@ describe Rackstash::Adapters::Null do
|
||||
|
||||
describe '.default_encoder' do
|
||||
it 'returns a Raw encoder' do
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoders::Raw
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoder::Raw
|
||||
end
|
||||
end
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/adapters'
|
||||
require 'rackstash/adapter'
|
||||
|
||||
describe Rackstash::Adapters do
|
||||
describe Rackstash::Adapter do
|
||||
around(:each) do |example|
|
||||
types = described_class.send(:adapter_types)
|
||||
schemes = described_class.send(:adapter_schemes)
|
||||
@ -24,7 +24,7 @@ describe Rackstash::Adapters do
|
||||
end
|
||||
|
||||
let(:adapter) {
|
||||
Class.new(Rackstash::Adapters::Adapter) do
|
||||
Class.new(Rackstash::Adapter::Adapter) do
|
||||
def self.from_uri(*args)
|
||||
new(*args)
|
||||
end
|
||||
@ -115,7 +115,7 @@ describe Rackstash::Adapters do
|
||||
|
||||
expect(device_class).to receive(:===).with(device).and_call_original
|
||||
expect(adapter).to receive(:new).with(device).and_call_original
|
||||
expect(described_class[device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[device]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
|
||||
it 'creates an adapter if any parent class was found' do
|
||||
@ -123,7 +123,7 @@ describe Rackstash::Adapters do
|
||||
|
||||
expect(device_class).to receive(:===).with(inherited_device).and_call_original
|
||||
expect(adapter).to receive(:new).with(inherited_device).and_call_original
|
||||
expect(described_class[inherited_device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[inherited_device]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
|
||||
it 'raises if no class was found' do
|
||||
@ -149,14 +149,14 @@ describe Rackstash::Adapters do
|
||||
device = SpecDevice.new
|
||||
|
||||
expect(adapter).to receive(:new).with(device).and_call_original
|
||||
expect(described_class[device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[device]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
|
||||
it 'creates an adapter if any parent class was found' do
|
||||
inherited_device = InheritedSpecDevice.new
|
||||
|
||||
expect(adapter).to receive(:new).with(inherited_device).and_call_original
|
||||
expect(described_class[inherited_device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[inherited_device]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
|
||||
it 'raises if no class was found' do
|
||||
@ -174,7 +174,7 @@ describe Rackstash::Adapters do
|
||||
device = Struct.new(:foo).new('foo')
|
||||
|
||||
expect(adapter).to receive(:new).with(device).and_call_original
|
||||
expect(described_class[device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[device]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
|
||||
it 'raises if it does not respond to the registered method' do
|
||||
@ -194,7 +194,7 @@ describe Rackstash::Adapters do
|
||||
|
||||
expect(checker).to receive(:===).with(device).and_call_original
|
||||
expect(adapter).to receive(:new).with(device).and_call_original
|
||||
expect(described_class[device]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[device]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
|
||||
it 'does not create an adapter if the proc returns false' do
|
||||
@ -215,11 +215,11 @@ describe Rackstash::Adapters do
|
||||
it 'creates an adapter from the scheme' do
|
||||
raw_uri = 'dummy://example.com'
|
||||
expect(adapter).to receive(:from_uri).with(URI(raw_uri)).and_call_original
|
||||
expect(described_class[raw_uri]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[raw_uri]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
|
||||
it 'calls adapter.new if adapter.from_uri is not available' do
|
||||
plain_adapter = Class.new(Rackstash::Adapters::Adapter)
|
||||
plain_adapter = Class.new(Rackstash::Adapter::Adapter)
|
||||
described_class.register plain_adapter, 'dummy'
|
||||
|
||||
raw_uri = 'dummy://example.com'
|
||||
@ -231,7 +231,7 @@ describe Rackstash::Adapters do
|
||||
it 'creates an adapter from a URI' do
|
||||
uri = URI('dummy://example.com')
|
||||
expect(adapter).to receive(:from_uri).with(uri).and_call_original
|
||||
expect(described_class[uri]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[uri]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
|
||||
it 'raises if no scheme was found' do
|
||||
@ -254,7 +254,7 @@ describe Rackstash::Adapters do
|
||||
expect(adapter).to_not receive(:from_uri)
|
||||
# from the fallback
|
||||
expect(adapter).to receive(:new).with(invalid_uri).and_call_original
|
||||
expect(described_class[invalid_uri]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[invalid_uri]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
|
||||
it 'falls though if no scheme was found' do
|
||||
@ -262,7 +262,7 @@ describe Rackstash::Adapters do
|
||||
|
||||
expect(adapter).to_not receive(:from_uri)
|
||||
expect(adapter).to receive(:new).with(unknown_uri).and_call_original
|
||||
expect(described_class[unknown_uri]).to be_an Rackstash::Adapters::Adapter
|
||||
expect(described_class[unknown_uri]).to be_an Rackstash::Adapter::Adapter
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/encoders/hash'
|
||||
require 'rackstash/encoder/hash'
|
||||
|
||||
describe Rackstash::Encoders::Hash do
|
||||
describe Rackstash::Encoder::Hash do
|
||||
let(:encoder) { described_class.new }
|
||||
|
||||
describe '#encode' do
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/encoders/helpers/message'
|
||||
require 'rackstash/encoder/helper/message'
|
||||
|
||||
describe Rackstash::Encoders::Helpers::Message do
|
||||
describe Rackstash::Encoder::Helper::Message do
|
||||
let(:helper) {
|
||||
helper = Object.new.extend(described_class)
|
||||
described_class.private_instance_methods(false).each do |method|
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/encoders/helpers/timestamp'
|
||||
require 'rackstash/encoder/helper/timestamp'
|
||||
|
||||
describe Rackstash::Encoders::Helpers::Timestamp do
|
||||
describe Rackstash::Encoder::Helper::Timestamp do
|
||||
let(:helper) {
|
||||
helper = Object.new.extend(described_class)
|
||||
described_class.private_instance_methods(false).each do |method|
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/encoders/json'
|
||||
require 'rackstash/encoder/json'
|
||||
|
||||
describe Rackstash::Encoders::JSON do
|
||||
describe Rackstash::Encoder::JSON do
|
||||
let(:encoder) { described_class.new }
|
||||
|
||||
describe '#encode' do
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/encoders/lograge'
|
||||
require 'rackstash/encoder/lograge'
|
||||
|
||||
describe Rackstash::Encoders::Lograge do
|
||||
describe Rackstash::Encoder::Lograge do
|
||||
let(:encoder) { described_class.new }
|
||||
|
||||
describe '#encode' do
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/encoders/logstash'
|
||||
require 'rackstash/encoder/logstash'
|
||||
|
||||
describe Rackstash::Encoders::Logstash do
|
||||
describe Rackstash::Encoder::Logstash do
|
||||
let(:encoder) { described_class.new }
|
||||
|
||||
describe '#encode' do
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/encoders/message'
|
||||
require 'rackstash/encoder/message'
|
||||
|
||||
describe Rackstash::Encoders::Message do
|
||||
describe Rackstash::Encoder::Message do
|
||||
let(:tagged) { [] }
|
||||
let(:encoder) { described_class.new(tagged: tagged) }
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'rackstash/encoders/raw'
|
||||
require 'rackstash/encoder/raw'
|
||||
|
||||
describe Rackstash::Encoders::Raw do
|
||||
describe Rackstash::Encoder::Raw do
|
||||
let(:encoder) { described_class.new }
|
||||
|
||||
describe '#encode' do
|
||||
@ -10,14 +10,14 @@ require 'spec_helper'
|
||||
require 'rackstash/flow'
|
||||
|
||||
describe Rackstash::Flow do
|
||||
let(:adapter) { Rackstash::Adapters::Null.new }
|
||||
let(:adapter) { Rackstash::Adapter::Null.new }
|
||||
let(:flow) { described_class.new(adapter) }
|
||||
let(:event) { {} }
|
||||
|
||||
describe '#initialize' do
|
||||
it 'creates an adapter' do
|
||||
expect(Rackstash::Adapters).to receive(:[]).with(nil).and_call_original
|
||||
expect(described_class.new(nil).adapter).to be_a Rackstash::Adapters::Null
|
||||
expect(Rackstash::Adapter).to receive(:[]).with(nil).and_call_original
|
||||
expect(described_class.new(nil).adapter).to be_a Rackstash::Adapter::Null
|
||||
end
|
||||
|
||||
it 'sets the default encoder from the adapter' do
|
||||
@ -28,7 +28,7 @@ describe Rackstash::Flow do
|
||||
end
|
||||
|
||||
it 'allows to set a custom encoder' do
|
||||
encoder = Rackstash::Encoders::Raw.new
|
||||
encoder = Rackstash::Encoder::Raw.new
|
||||
flow = described_class.new(adapter, encoder: encoder)
|
||||
|
||||
expect(flow.encoder).to equal encoder
|
||||
@ -117,7 +117,7 @@ describe Rackstash::Flow do
|
||||
end
|
||||
|
||||
it 'allows to set a new encoder' do
|
||||
encoder = Rackstash::Encoders::JSON.new
|
||||
encoder = Rackstash::Encoder::JSON.new
|
||||
expect(flow.encoder(encoder)).to equal encoder
|
||||
|
||||
# The encoder is persisted and is returned afterwards
|
||||
@ -127,7 +127,7 @@ describe Rackstash::Flow do
|
||||
|
||||
describe '#encoder=' do
|
||||
it 'sets a new encoder' do
|
||||
encoder = Rackstash::Encoders::JSON.new
|
||||
encoder = Rackstash::Encoder::JSON.new
|
||||
flow.encoder = encoder
|
||||
|
||||
expect(flow.encoder).to equal encoder
|
||||
|
||||
@ -140,8 +140,8 @@ describe Rackstash do
|
||||
it 'returns a default Flow' do
|
||||
expect(described_class.error_flow).to be_instance_of Rackstash::Flow
|
||||
|
||||
expect(described_class.error_flow.encoder).to be_instance_of Rackstash::Encoders::JSON
|
||||
expect(described_class.error_flow.adapter).to be_instance_of Rackstash::Adapters::IO
|
||||
expect(described_class.error_flow.encoder).to be_instance_of Rackstash::Encoder::JSON
|
||||
expect(described_class.error_flow.adapter).to be_instance_of Rackstash::Adapter::IO
|
||||
end
|
||||
|
||||
it 'caches the flow' do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user