Skip to content

Commit 2c1e8cb

Browse files
klausmeyerjordansissel
authored andcommitted
rename option to skip_on_invalid_json
Fixes #24
1 parent fc430e9 commit 2c1e8cb

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lib/logstash/filters/json.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class LogStash::Filters::Json < LogStash::Filters::Base
5959
# successful match
6060
config :tag_on_failure, :validate => :array, :default => ["_jsonparsefailure"]
6161

62-
# Allow to quietly fall-back to plain-text (aka skip the filter without warnings and tags)
63-
config :fallback_mode, :validate => :boolean, :default => false
62+
# Allow to skip filter on invalid json (allows to handle json and non-json data without warnings)
63+
config :skip_on_invalid_json, :validate => :boolean, :default => false
6464

6565
def register
6666
# Nothing to do here
@@ -75,7 +75,7 @@ def filter(event)
7575
begin
7676
parsed = LogStash::Json.load(source)
7777
rescue => e
78-
unless @fallback_mode
78+
unless @skip_on_invalid_json
7979
@tag_on_failure.each{|tag| event.tag(tag)}
8080
@logger.warn("Error parsing json", :source => @source, :raw => source, :exception => e)
8181
end

spec/filters/json_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@
176176
end
177177
end
178178

179-
describe "parse mixture of json an non-json content (fallback mode)" do
179+
describe "parse mixture of json an non-json content (skip_on_invalid_json)" do
180180
subject(:filter) { LogStash::Filters::Json.new(config) }
181181

182-
let(:config) { {"source" => "message", "remove_field" => ["message"], "fallback_mode" => fallback_mode} }
182+
let(:config) { {"source" => "message", "remove_field" => ["message"], "skip_on_invalid_json" => skip_on_invalid_json} }
183183
let(:event) { LogStash::Event.new("message" => message) }
184184

185185
before(:each) do
@@ -190,8 +190,8 @@
190190

191191
let(:message) { "this is not a json message" }
192192

193-
context "with fallback_mode off" do
194-
let(:fallback_mode) { false }
193+
context "with `skip_on_invalid_json` set to false" do
194+
let(:skip_on_invalid_json) { false }
195195

196196
it "sends a warning to the logger" do
197197
expect(filter.logger).to have_received(:warn).with("Error parsing json", anything())
@@ -206,8 +206,8 @@
206206
end
207207
end
208208

209-
context "with fallback_mode on" do
210-
let(:fallback_mode) { true }
209+
context "with `skip_on_invalid_json` set to true" do
210+
let(:skip_on_invalid_json) { true }
211211

212212
it "sends no warning" do
213213
expect(filter.logger).to_not have_received(:warn)

0 commit comments

Comments
 (0)