Skip to content

Commit

Permalink
Remove rackstash_buffering setting as the base feature was removed fr…
Browse files Browse the repository at this point in the history
…om Rackstash
  • Loading branch information
meineerde committed Apr 20, 2018
1 parent acf8fa9 commit 15db784
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 48 deletions.
19 changes: 6 additions & 13 deletions lib/rackstash/sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ module Rackstash
# (e.g. an `IO` object or the name of a log file) which can be used to
# create a suitable Rackstash adapter with a new `Rackstash::Logger` object
# for use by the middleware.
# * `rackstash_buffering => Symbol, Boolean` - defines the buffering mode of
# buffers created by the {Rackstash::Sinatra::Middleware} for each request.
# You can set it to `:full` to emit only a single log event per request, to
# `:data` to accumulate fields and tags on the request's buffer but to emit
# a new log event per logged message, or to `:none` to emit log events for
# each message and to clear the buffer afterwards. See the Rackstash
# documentation of `Rackstash::Buffer#buffering` for details.
# * `rackstash_request_fields => Hash<#to_s, => Proc, Object>, Fields::Hash, Proc` -
# Additional fields to merge into the emitted log event before processing
# the request. If the object itself or any of its hash values is a `Proc`,
Expand Down Expand Up @@ -115,13 +108,15 @@ module Rackstash
# enable that, you configure the Rackstash logger to output only the messages
# as soon as they are logged. A suitable configuration can look like this:
#
# # First, we define a suitable Rackstash logger
# logger = Rackstash::Logger.new(STDOUT, level: Rackstash::INFO) do |flow|
# flow.encoder Rackstash::Encoder::Message.new(['@timestamp'])
# flow.auto_flush!
# end
# set :rackstash, logger
#
# # Then, we enable logging in Sinatra
# set :logging, true
# set :rackstash, logger
# set :rackstash_buffering, :data
module Sinatra
# Callback method called by Sinatra when registering this class as a plugin
# in a Sinatra application. Here, we are setting the default values for
Expand All @@ -131,7 +126,6 @@ module Sinatra
# @return [void]
def self.registered(app)
app.set :rackstash, STDOUT
app.set :rackstash_buffering, :full

app.set :rackstash_request_fields, nil
app.set :rackstash_request_tags, nil
Expand All @@ -152,8 +146,8 @@ def self.registered(app)
# (e.g. with the `rackup` command and a `config.ru` file). When starting
# the server directly from Sinatra with e.g. `ruby app.rb`, the default
# options of Rack are not used. We thus have to provide our own sensible
# defaults to disable the unecessary default access logs of WEBrick in all
# cases.
# defaults to disable the unnecessary default access logs of WEBrick in
# all cases.
app.set :server_settings, {} unless app.settings.respond_to?(:server_settings)
app.server_settings[:AccessLog] ||= [] if app.server_settings.respond_to?(:[]=)
end
Expand Down Expand Up @@ -191,7 +185,6 @@ def setup_logging(builder) # :doc:
builder.use(
Rackstash::Sinatra::Middleware,
logger,
buffering: rackstash_buffering,
request_fields: rackstash_request_fields,
request_tags: rackstash_request_tags,
response_fields: rackstash_response_fields,
Expand Down
35 changes: 0 additions & 35 deletions spec/rackstash/sinatra_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

it 'sets default settings' do
expect(app.rackstash).to equal STDOUT
expect(app.rackstash_buffering).to eql :full
expect(app.rackstash_request_fields).to be_nil
expect(app.rackstash_request_tags).to be_nil
expect(app.rackstash_response_fields).to be_nil
Expand Down Expand Up @@ -166,40 +165,6 @@ def perform_request
end
end

describe '.rackstash_buffering' do
let(:app) {
sinatra_app(sinatra_base) do
get '/' do
logger.info('Starting...')
logger.warn('Hello')
logger.info('All done')
end
end
}

it 'can output multiple messages' do
stream = StringIO.new
adapter = Rackstash::Adapter[stream]

logger = Rackstash::Logger.new(adapter) do
encoder Rackstash::Encoder::Message.new
end
app.rackstash = logger
app.enable :logging

# Write each message individually plus the final "empty" message
app.rackstash_buffering = :data
expect(adapter).to receive(:write).exactly(4).times.and_call_original

expect(perform_request).to eql 200
expect(stream.string.each_line.to_a).to eql [
"Starting...\n",
"Hello\n",
"All done\n"
]
end
end

context 'with additional fields' do
let(:logs) { [] }

Expand Down

0 comments on commit 15db784

Please sign in to comment.