mirror of
https://github.com/meineerde/rackstash.git
synced 2025-12-19 15:01:12 +00:00
Add Null adapter which just swallows any logs
This commit is contained in:
parent
ca339a84fa
commit
b573581a26
@ -89,3 +89,4 @@ require 'rackstash/logger'
|
||||
require 'rackstash/adapters/callable'
|
||||
require 'rackstash/adapters/file'
|
||||
require 'rackstash/adapters/io'
|
||||
require 'rackstash/adapters/null'
|
||||
|
||||
43
lib/rackstash/adapters/null.rb
Normal file
43
lib/rackstash/adapters/null.rb
Normal file
@ -0,0 +1,43 @@
|
||||
# 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/adapters/adapter'
|
||||
require 'rackstash/encoders/raw'
|
||||
|
||||
module Rackstash
|
||||
module Adapters
|
||||
# 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
|
||||
# the {Flow} pipeline.
|
||||
class Null < Adapter
|
||||
register_for NilClass
|
||||
|
||||
# Create a new black hole adapter. Any logs written to it will be
|
||||
# swallowed and not written anywhere.
|
||||
def initialize(*)
|
||||
end
|
||||
|
||||
# By default, we use a {Rackstash::Encoders::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
|
||||
def default_encoder
|
||||
Rackstash::Encoders::Raw.new
|
||||
end
|
||||
|
||||
# Swallow a log event. It is not written anywhere.
|
||||
#
|
||||
# @param log [Object] the encoded log event
|
||||
# @return [nil]
|
||||
def write_single(log)
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
45
spec/rackstash/adapters/null_spec.rb
Normal file
45
spec/rackstash/adapters/null_spec.rb
Normal file
@ -0,0 +1,45 @@
|
||||
# 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 'spec_helper'
|
||||
|
||||
require 'rackstash/adapters/null'
|
||||
|
||||
describe Rackstash::Adapters::Null do
|
||||
let(:adapter) { described_class.new }
|
||||
|
||||
describe '#initialize' do
|
||||
it 'accepts and ignores any arguments' do
|
||||
expect { described_class.new }.not_to raise_error
|
||||
expect { described_class.new(:foo, :bar, :baz) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe '.default_encoder' do
|
||||
it 'returns a Raw encoder' do
|
||||
expect(adapter.default_encoder).to be_instance_of Rackstash::Encoders::Raw
|
||||
end
|
||||
end
|
||||
|
||||
describe '#close' do
|
||||
it 'does nothing' do
|
||||
expect { adapter.close }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe '#reopen' do
|
||||
it 'does nothing' do
|
||||
expect { adapter.reopen }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe '#write_single' do
|
||||
it 'does nothing' do
|
||||
expect { adapter.write('a log line') }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user