Permalink
Browse files

Fix nil pointer error when log_level set to :off

[#151543029]

Signed-off-by: Lyle Franklin <lfranklin@pivotal.io>
  • Loading branch information...
1 parent 506c505 commit e2c9408c1d255ff4a9952bdced9684bec666d4d6 @ericpromislow ericpromislow committed with ljfranklin Oct 20, 2017
Showing with 26 additions and 1 deletion.
  1. +1 −0 lib/steno/sink/syslog.rb
  2. +1 −1 lib/steno/version.rb
  3. +24 −0 spec/unit/sink/syslog_spec.rb
View
@@ -36,6 +36,7 @@ def open(identity)
end
def add_record(record)
+ return if record.log_level == :off
record = truncate_record(record)
msg = @codec.encode_record(record)
pri = LOG_LEVEL_MAP[record.log_level]
View
@@ -1,3 +1,3 @@
module Steno
- VERSION = "1.3.4"
+ VERSION = "1.3.5"
end
@@ -64,6 +64,30 @@
sink.add_record(record_with_big_message)
end
+
+ context "when level is off" do
+ let(:level) do
+ Steno::Logger.lookup_level(:off)
+ end
+
+ it "should not write out logs" do
+ identity = "test"
+
+ syslog = double("syslog", facility: nil, log: nil)
+ expect(Syslog).to receive(:open).and_return(syslog)
+
+ sink = Steno::Sink::Syslog.instance
+ sink.open(identity)
+
+ codec = double("codec", encode_record: nil)
+ sink.codec = codec
+
+ sink.add_record(record)
+
+ expect(codec).to_not have_received(:encode_record)
+ expect(syslog).to_not have_received(:log)
+ end
+ end
end
describe "#flush" do

0 comments on commit e2c9408

Please sign in to comment.