spec/timber/logger_spec.rb in timber-1.0.3 vs spec/timber/logger_spec.rb in timber-1.0.4
- old
+ new
@@ -27,11 +27,11 @@
request_id: "abcd1234"
)
end
around(:each) do |example|
- Timber::CurrentContext.instance.with(http_context) do
+ Timber::CurrentContext.with(http_context) do
example.run
end
end
it "should snapshot and include the context" do
@@ -74,16 +74,28 @@
logger.info("this is a test")
expect(io.string).to eq("{\"level\":\"info\",\"dt\":\"2016-09-01T12:00:00.000000Z\",\"message\":\"this is a test\"}\n")
end
end
- context "with TaggedLogging" do
- let(:logger) { ActiveSupport::TaggedLogging.new(Timber::Logger.new(io)) }
+ if defined?(ActiveSupport::TaggedLogging)
+ context "with TaggedLogging", :rails_23 => false do
+ let(:logger) { ActiveSupport::TaggedLogging.new(Timber::Logger.new(io)) }
- it "should format properly with events" do
- message = Timber::Events::SQLQuery.new(sql: "select * from users", time_ms: 56, message: "select * from users")
- logger.info(message)
- expect(io.string).to eq("select * from users @timber.io {\"level\":\"info\",\"dt\":\"2016-09-01T12:00:00.000000Z\",\"event\":{\"sql_query\":{\"sql\":\"select * from users\",\"time_ms\":56}}}\n")
+ it "should format properly with events" do
+ message = Timber::Events::SQLQuery.new(sql: "select * from users", time_ms: 56, message: "select * from users")
+ logger.tagged("tag") do
+ logger.info(message)
+ end
+ expect(io.string).to eq("select * from users @timber.io {\"level\":\"info\",\"dt\":\"2016-09-01T12:00:00.000000Z\",\"event\":{\"sql_query\":{\"sql\":\"select * from users\",\"time_ms\":56}},\"context\":{\"tags\":[\"tag\"]}}\n")
+ end
+ end
+ end
+
+ context "with the HTTP log device" do
+ let(:io) { Timber::LogDevices::HTTP.new("my_key") }
+
+ it "should use the msgpack formatter" do
+ expect(logger.formatter).to be_kind_of(Timber::Logger::MsgPackFormatter)
end
end
end
end
\ No newline at end of file