diff --git a/lib/rackstash.rb b/lib/rackstash.rb index 40ca2a4..29f50e8 100644 --- a/lib/rackstash.rb +++ b/lib/rackstash.rb @@ -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' diff --git a/lib/rackstash/adapters.rb b/lib/rackstash/adapter.rb similarity index 93% rename from lib/rackstash/adapters.rb rename to lib/rackstash/adapter.rb index 45bdaa8..90d7c29 100644 --- a/lib/rackstash/adapters.rb +++ b/lib/rackstash/adapter.rb @@ -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] 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) diff --git a/lib/rackstash/adapters/adapter.rb b/lib/rackstash/adapter/adapter.rb similarity index 87% rename from lib/rackstash/adapters/adapter.rb rename to lib/rackstash/adapter/adapter.rb index 4b59e61..b80cf27 100644 --- a/lib/rackstash/adapters/adapter.rb +++ b/lib/rackstash/adapter/adapter.rb @@ -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. diff --git a/lib/rackstash/adapters/callable.rb b/lib/rackstash/adapter/callable.rb similarity index 81% rename from lib/rackstash/adapters/callable.rb rename to lib/rackstash/adapter/callable.rb index 935e4d5..dd0461e 100644 --- a/lib/rackstash/adapters/callable.rb +++ b/lib/rackstash/adapter/callable.rb @@ -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 diff --git a/lib/rackstash/adapters/file.rb b/lib/rackstash/adapter/file.rb similarity index 97% rename from lib/rackstash/adapters/file.rb rename to lib/rackstash/adapter/file.rb index 9890fa3..49036c6 100644 --- a/lib/rackstash/adapters/file.rb +++ b/lib/rackstash/adapter/file.rb @@ -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 diff --git a/lib/rackstash/adapters/io.rb b/lib/rackstash/adapter/io.rb similarity index 94% rename from lib/rackstash/adapters/io.rb rename to lib/rackstash/adapter/io.rb index dbd44fa..e56f7be 100644 --- a/lib/rackstash/adapters/io.rb +++ b/lib/rackstash/adapter/io.rb @@ -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. # diff --git a/lib/rackstash/adapters/logger.rb b/lib/rackstash/adapter/logger.rb similarity index 98% rename from lib/rackstash/adapters/logger.rb rename to lib/rackstash/adapter/logger.rb index 41d9a3b..67eb833 100644 --- a/lib/rackstash/adapters/logger.rb +++ b/lib/rackstash/adapter/logger.rb @@ -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 diff --git a/lib/rackstash/adapters/null.rb b/lib/rackstash/adapter/null.rb similarity index 78% rename from lib/rackstash/adapters/null.rb rename to lib/rackstash/adapter/null.rb index 4005e0e..2e33b51 100644 --- a/lib/rackstash/adapters/null.rb +++ b/lib/rackstash/adapter/null.rb @@ -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. diff --git a/lib/rackstash/encoder.rb b/lib/rackstash/encoder.rb new file mode 100644 index 0000000..7a118ae --- /dev/null +++ b/lib/rackstash/encoder.rb @@ -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' diff --git a/lib/rackstash/encoders/hash.rb b/lib/rackstash/encoder/hash.rb similarity index 76% rename from lib/rackstash/encoders/hash.rb rename to lib/rackstash/encoder/hash.rb index 5811228..2ef701f 100644 --- a/lib/rackstash/encoders/hash.rb +++ b/lib/rackstash/encoder/hash.rb @@ -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 diff --git a/lib/rackstash/encoders/helpers/message.rb b/lib/rackstash/encoder/helper/message.rb similarity index 87% rename from lib/rackstash/encoders/helpers/message.rb rename to lib/rackstash/encoder/helper/message.rb index 014e14a..3be19df 100644 --- a/lib/rackstash/encoders/helpers/message.rb +++ b/lib/rackstash/encoder/helper/message.rb @@ -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 diff --git a/lib/rackstash/encoders/helpers/timestamp.rb b/lib/rackstash/encoder/helper/timestamp.rb similarity index 85% rename from lib/rackstash/encoders/helpers/timestamp.rb rename to lib/rackstash/encoder/helper/timestamp.rb index f3b65e4..7f7f190 100644 --- a/lib/rackstash/encoders/helpers/timestamp.rb +++ b/lib/rackstash/encoder/helper/timestamp.rb @@ -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 diff --git a/lib/rackstash/encoders/json.rb b/lib/rackstash/encoder/json.rb similarity index 71% rename from lib/rackstash/encoders/json.rb rename to lib/rackstash/encoder/json.rb index a5373ab..99edfbf 100644 --- a/lib/rackstash/encoders/json.rb +++ b/lib/rackstash/encoder/json.rb @@ -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 diff --git a/lib/rackstash/encoders/lograge.rb b/lib/rackstash/encoder/lograge.rb similarity index 97% rename from lib/rackstash/encoders/lograge.rb rename to lib/rackstash/encoder/lograge.rb index 47f77da..814ca5f 100644 --- a/lib/rackstash/encoders/lograge.rb +++ b/lib/rackstash/encoder/lograge.rb @@ -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, diff --git a/lib/rackstash/encoders/logstash.rb b/lib/rackstash/encoder/logstash.rb similarity index 95% rename from lib/rackstash/encoders/logstash.rb rename to lib/rackstash/encoder/logstash.rb index 484b5ee..953f003 100644 --- a/lib/rackstash/encoders/logstash.rb +++ b/lib/rackstash/encoder/logstash.rb @@ -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 diff --git a/lib/rackstash/encoders/message.rb b/lib/rackstash/encoder/message.rb similarity index 91% rename from lib/rackstash/encoders/message.rb rename to lib/rackstash/encoder/message.rb index 98e71ea..fed45a4 100644 --- a/lib/rackstash/encoders/message.rb +++ b/lib/rackstash/encoder/message.rb @@ -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 diff --git a/lib/rackstash/encoders/raw.rb b/lib/rackstash/encoder/raw.rb similarity index 90% rename from lib/rackstash/encoders/raw.rb rename to lib/rackstash/encoder/raw.rb index 2f53188..18110c9 100644 --- a/lib/rackstash/encoders/raw.rb +++ b/lib/rackstash/encoder/raw.rb @@ -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` diff --git a/lib/rackstash/encoders.rb b/lib/rackstash/encoders.rb deleted file mode 100644 index 485a8f6..0000000 --- a/lib/rackstash/encoders.rb +++ /dev/null @@ -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' diff --git a/lib/rackstash/flow.rb b/lib/rackstash/flow.rb index 0a2901c..1c9beb9 100644 --- a/lib/rackstash/flow.rb +++ b/lib/rackstash/flow.rb @@ -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 diff --git a/lib/rackstash/flows.rb b/lib/rackstash/flows.rb index 6ca3556..bcdbd5a 100644 --- a/lib/rackstash/flows.rb +++ b/lib/rackstash/flows.rb @@ -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] the {Flow} objects + # @param flows [::Array] 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] diff --git a/lib/rackstash/logger.rb b/lib/rackstash/logger.rb index a2a2f42..4773613 100644 --- a/lib/rackstash/logger.rb +++ b/lib/rackstash/logger.rb @@ -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, Adapters::Adapter, Object] + # @param flows [Array, 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 diff --git a/spec/rackstash/adapters/adapter_spec.rb b/spec/rackstash/adapter/adapter_spec.rb similarity index 93% rename from spec/rackstash/adapters/adapter_spec.rb rename to spec/rackstash/adapter/adapter_spec.rb index ad6efd1..9d80ca1 100644 --- a/spec/rackstash/adapters/adapter_spec.rb +++ b/spec/rackstash/adapter/adapter_spec.rb @@ -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 diff --git a/spec/rackstash/adapters/callable_spec.rb b/spec/rackstash/adapter/callable_spec.rb similarity index 94% rename from spec/rackstash/adapters/callable_spec.rb rename to spec/rackstash/adapter/callable_spec.rb index 40b8886..285ca3c 100644 --- a/spec/rackstash/adapters/callable_spec.rb +++ b/spec/rackstash/adapter/callable_spec.rb @@ -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 diff --git a/spec/rackstash/adapters/file_spec.rb b/spec/rackstash/adapter/file_spec.rb similarity index 98% rename from spec/rackstash/adapters/file_spec.rb rename to spec/rackstash/adapter/file_spec.rb index 248b23e..a211f9a 100644 --- a/spec/rackstash/adapters/file_spec.rb +++ b/spec/rackstash/adapter/file_spec.rb @@ -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 diff --git a/spec/rackstash/adapters/io_spec.rb b/spec/rackstash/adapter/io_spec.rb similarity index 96% rename from spec/rackstash/adapters/io_spec.rb rename to spec/rackstash/adapter/io_spec.rb index ec67f24..8f8f528 100644 --- a/spec/rackstash/adapters/io_spec.rb +++ b/spec/rackstash/adapter/io_spec.rb @@ -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 diff --git a/spec/rackstash/adapters/logger_spec.rb b/spec/rackstash/adapter/logger_spec.rb similarity index 97% rename from spec/rackstash/adapters/logger_spec.rb rename to spec/rackstash/adapter/logger_spec.rb index b8e59b2..eaeeca1 100644 --- a/spec/rackstash/adapters/logger_spec.rb +++ b/spec/rackstash/adapter/logger_spec.rb @@ -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 diff --git a/spec/rackstash/adapters/null_spec.rb b/spec/rackstash/adapter/null_spec.rb similarity index 91% rename from spec/rackstash/adapters/null_spec.rb rename to spec/rackstash/adapter/null_spec.rb index 5c1f212..13b7bb2 100644 --- a/spec/rackstash/adapters/null_spec.rb +++ b/spec/rackstash/adapter/null_spec.rb @@ -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 diff --git a/spec/rackstash/adapters_spec.rb b/spec/rackstash/adapter_spec.rb similarity index 96% rename from spec/rackstash/adapters_spec.rb rename to spec/rackstash/adapter_spec.rb index 496c6bd..5321564 100644 --- a/spec/rackstash/adapters_spec.rb +++ b/spec/rackstash/adapter_spec.rb @@ -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 diff --git a/spec/rackstash/encoders/hash_spec.rb b/spec/rackstash/encoder/hash_spec.rb similarity index 92% rename from spec/rackstash/encoders/hash_spec.rb rename to spec/rackstash/encoder/hash_spec.rb index 6fac629..8701b53 100644 --- a/spec/rackstash/encoders/hash_spec.rb +++ b/spec/rackstash/encoder/hash_spec.rb @@ -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 diff --git a/spec/rackstash/encoders/helpers/message_spec.rb b/spec/rackstash/encoder/helper/message_spec.rb similarity index 92% rename from spec/rackstash/encoders/helpers/message_spec.rb rename to spec/rackstash/encoder/helper/message_spec.rb index 7fa823f..d9bd784 100644 --- a/spec/rackstash/encoders/helpers/message_spec.rb +++ b/spec/rackstash/encoder/helper/message_spec.rb @@ -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| diff --git a/spec/rackstash/encoders/helpers/timestamp_spec.rb b/spec/rackstash/encoder/helper/timestamp_spec.rb similarity index 94% rename from spec/rackstash/encoders/helpers/timestamp_spec.rb rename to spec/rackstash/encoder/helper/timestamp_spec.rb index 74bb34c..4b03d94 100644 --- a/spec/rackstash/encoders/helpers/timestamp_spec.rb +++ b/spec/rackstash/encoder/helper/timestamp_spec.rb @@ -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| diff --git a/spec/rackstash/encoders/json_spec.rb b/spec/rackstash/encoder/json_spec.rb similarity index 90% rename from spec/rackstash/encoders/json_spec.rb rename to spec/rackstash/encoder/json_spec.rb index 56933ba..aac29d6 100644 --- a/spec/rackstash/encoders/json_spec.rb +++ b/spec/rackstash/encoder/json_spec.rb @@ -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 diff --git a/spec/rackstash/encoders/lograge_spec.rb b/spec/rackstash/encoder/lograge_spec.rb similarity index 96% rename from spec/rackstash/encoders/lograge_spec.rb rename to spec/rackstash/encoder/lograge_spec.rb index d584760..cff1e8b 100644 --- a/spec/rackstash/encoders/lograge_spec.rb +++ b/spec/rackstash/encoder/lograge_spec.rb @@ -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 diff --git a/spec/rackstash/encoders/logstash_spec.rb b/spec/rackstash/encoder/logstash_spec.rb similarity index 88% rename from spec/rackstash/encoders/logstash_spec.rb rename to spec/rackstash/encoder/logstash_spec.rb index dbdf22d..b5819f0 100644 --- a/spec/rackstash/encoders/logstash_spec.rb +++ b/spec/rackstash/encoder/logstash_spec.rb @@ -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 diff --git a/spec/rackstash/encoders/message_spec.rb b/spec/rackstash/encoder/message_spec.rb similarity index 96% rename from spec/rackstash/encoders/message_spec.rb rename to spec/rackstash/encoder/message_spec.rb index a555ae2..d0e9f26 100644 --- a/spec/rackstash/encoders/message_spec.rb +++ b/spec/rackstash/encoder/message_spec.rb @@ -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) } diff --git a/spec/rackstash/encoders/raw_spec.rb b/spec/rackstash/encoder/raw_spec.rb similarity index 85% rename from spec/rackstash/encoders/raw_spec.rb rename to spec/rackstash/encoder/raw_spec.rb index adace03..356119a 100644 --- a/spec/rackstash/encoders/raw_spec.rb +++ b/spec/rackstash/encoder/raw_spec.rb @@ -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 diff --git a/spec/rackstash/flow_spec.rb b/spec/rackstash/flow_spec.rb index 764233d..4abb234 100644 --- a/spec/rackstash/flow_spec.rb +++ b/spec/rackstash/flow_spec.rb @@ -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 diff --git a/spec/rackstash_spec.rb b/spec/rackstash_spec.rb index 006068e..5a9beae 100644 --- a/spec/rackstash_spec.rb +++ b/spec/rackstash_spec.rb @@ -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