timberio 1.0.0.beta1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -2
  3. data/.rspec +2 -0
  4. data/.yardopts +6 -0
  5. data/Appraisals +4 -0
  6. data/Gemfile +9 -1
  7. data/LICENSE.md +15 -0
  8. data/README.md +170 -8
  9. data/circle.yml +11 -8
  10. data/lib/timber/config.rb +11 -18
  11. data/lib/timber/context.rb +9 -68
  12. data/lib/timber/contexts/custom.rb +27 -0
  13. data/lib/timber/contexts/http.rb +28 -0
  14. data/lib/timber/contexts/organization.rb +24 -22
  15. data/lib/timber/contexts/user.rb +25 -28
  16. data/lib/timber/contexts.rb +7 -20
  17. data/lib/timber/current_context.rb +26 -41
  18. data/lib/timber/event.rb +13 -0
  19. data/lib/timber/events/controller_call.rb +40 -0
  20. data/lib/timber/events/custom.rb +42 -0
  21. data/lib/timber/events/exception.rb +35 -0
  22. data/lib/timber/events/http_request.rb +50 -0
  23. data/lib/timber/events/http_response.rb +36 -0
  24. data/lib/timber/events/sql_query.rb +26 -0
  25. data/lib/timber/events/template_render.rb +26 -0
  26. data/lib/timber/events.rb +37 -0
  27. data/lib/timber/frameworks/rails.rb +3 -14
  28. data/lib/timber/frameworks.rb +8 -10
  29. data/lib/timber/log_devices/http.rb +72 -13
  30. data/lib/timber/log_devices.rb +8 -4
  31. data/lib/timber/log_entry.rb +59 -0
  32. data/lib/timber/logger.rb +136 -13
  33. data/lib/timber/probe.rb +6 -4
  34. data/lib/timber/probes/action_controller_log_subscriber/log_subscriber.rb +64 -0
  35. data/lib/timber/probes/action_controller_log_subscriber.rb +20 -0
  36. data/lib/timber/probes/action_dispatch_debug_exceptions.rb +59 -35
  37. data/lib/timber/probes/action_view_log_subscriber/log_subscriber.rb +62 -0
  38. data/lib/timber/probes/action_view_log_subscriber.rb +20 -0
  39. data/lib/timber/probes/active_record_log_subscriber/log_subscriber.rb +72 -0
  40. data/lib/timber/probes/active_record_log_subscriber.rb +20 -0
  41. data/lib/timber/probes/rack_http_context.rb +51 -0
  42. data/lib/timber/probes/rails_rack_logger.rb +76 -0
  43. data/lib/timber/probes.rb +13 -16
  44. data/lib/timber/util/active_support_log_subscriber.rb +33 -0
  45. data/lib/timber/util/hash.rb +14 -0
  46. data/lib/timber/util.rb +8 -0
  47. data/lib/timber/version.rb +2 -2
  48. data/lib/timber.rb +6 -11
  49. data/spec/spec_helper.rb +7 -4
  50. data/spec/support/rails.rb +9 -5
  51. data/spec/support/timber.rb +1 -20
  52. data/spec/timber/events_spec.rb +55 -0
  53. data/spec/timber/log_devices/http_spec.rb +62 -0
  54. data/spec/timber/logger_spec.rb +68 -0
  55. data/spec/timber/probes/action_controller_log_subscriber_spec.rb +70 -0
  56. data/spec/timber/probes/action_dispatch_debug_exceptions_spec.rb +24 -18
  57. data/spec/timber/probes/action_view_log_subscriber_spec.rb +61 -0
  58. data/spec/timber/probes/active_record_log_subscriber_spec.rb +49 -0
  59. data/spec/timber/probes/rack_http_context_spec.rb +54 -0
  60. data/spec/timber/probes/rails_rack_logger_spec.rb +46 -0
  61. data/timberio.gemspec +2 -0
  62. metadata +62 -123
  63. data/.codeclimate.yml +0 -34
  64. data/LICENSE +0 -38
  65. data/Rakefile +0 -4
  66. data/TODO +0 -4
  67. data/benchmark/README.md +0 -26
  68. data/benchmark/rails_request.rb +0 -68
  69. data/benchmark/support/rails.rb +0 -69
  70. data/docs/installation/rails_on_heroku.md +0 -31
  71. data/docs/installation/rails_over_http.md +0 -22
  72. data/gemfiles/rails_3.0.X.gemfile +0 -25
  73. data/gemfiles/rails_3.1.X.gemfile +0 -25
  74. data/gemfiles/rails_3.2.X.gemfile +0 -25
  75. data/gemfiles/rails_4.0.X.gemfile +0 -26
  76. data/gemfiles/rails_4.1.X.gemfile +0 -26
  77. data/gemfiles/rails_4.2.X.gemfile +0 -26
  78. data/gemfiles/rails_5.0.X.gemfile +0 -26
  79. data/gemfiles/rails_edge.gemfile +0 -27
  80. data/lib/timber/api_settings.rb +0 -17
  81. data/lib/timber/bootstrap.rb +0 -45
  82. data/lib/timber/context_snapshot.rb +0 -64
  83. data/lib/timber/contexts/dynamic_values.rb +0 -59
  84. data/lib/timber/contexts/exception.rb +0 -40
  85. data/lib/timber/contexts/http_request.rb +0 -22
  86. data/lib/timber/contexts/http_requests/action_controller_specific.rb +0 -48
  87. data/lib/timber/contexts/http_requests/rack/params.rb +0 -26
  88. data/lib/timber/contexts/http_requests/rack.rb +0 -105
  89. data/lib/timber/contexts/http_response.rb +0 -19
  90. data/lib/timber/contexts/http_responses/action_controller.rb +0 -76
  91. data/lib/timber/contexts/logger.rb +0 -33
  92. data/lib/timber/contexts/organizations/action_controller.rb +0 -34
  93. data/lib/timber/contexts/server.rb +0 -21
  94. data/lib/timber/contexts/servers/heroku_specific.rb +0 -48
  95. data/lib/timber/contexts/sql_queries/active_record.rb +0 -30
  96. data/lib/timber/contexts/sql_queries/active_record_specific/binds.rb +0 -37
  97. data/lib/timber/contexts/sql_queries/active_record_specific.rb +0 -59
  98. data/lib/timber/contexts/sql_query.rb +0 -18
  99. data/lib/timber/contexts/template_render.rb +0 -17
  100. data/lib/timber/contexts/template_renders/action_view.rb +0 -29
  101. data/lib/timber/contexts/template_renders/action_view_specific.rb +0 -51
  102. data/lib/timber/contexts/users/action_controller.rb +0 -34
  103. data/lib/timber/current_line_indexes.rb +0 -35
  104. data/lib/timber/internal_logger.rb +0 -35
  105. data/lib/timber/log_device.rb +0 -40
  106. data/lib/timber/log_devices/heroku_logplex/hybrid_formatter.rb +0 -14
  107. data/lib/timber/log_devices/heroku_logplex.rb +0 -14
  108. data/lib/timber/log_devices/http/log_pile.rb +0 -86
  109. data/lib/timber/log_devices/http/log_truck/delivery.rb +0 -116
  110. data/lib/timber/log_devices/http/log_truck.rb +0 -87
  111. data/lib/timber/log_devices/io/formatter.rb +0 -46
  112. data/lib/timber/log_devices/io/hybrid_formatter.rb +0 -41
  113. data/lib/timber/log_devices/io/hybrid_hidden_formatter.rb +0 -36
  114. data/lib/timber/log_devices/io/json_formatter.rb +0 -11
  115. data/lib/timber/log_devices/io/logfmt_formatter.rb +0 -11
  116. data/lib/timber/log_devices/io.rb +0 -41
  117. data/lib/timber/log_line.rb +0 -33
  118. data/lib/timber/macros/compactor.rb +0 -16
  119. data/lib/timber/macros/date_formatter.rb +0 -9
  120. data/lib/timber/macros/deep_merger.rb +0 -11
  121. data/lib/timber/macros/logfmt_encoder.rb +0 -77
  122. data/lib/timber/macros.rb +0 -4
  123. data/lib/timber/patterns/delegated_singleton.rb +0 -21
  124. data/lib/timber/patterns/to_json.rb +0 -22
  125. data/lib/timber/patterns/to_logfmt.rb +0 -9
  126. data/lib/timber/patterns.rb +0 -3
  127. data/lib/timber/probes/action_controller_base.rb +0 -31
  128. data/lib/timber/probes/active_support_log_subscriber/action_controller.rb +0 -15
  129. data/lib/timber/probes/active_support_log_subscriber/action_view.rb +0 -26
  130. data/lib/timber/probes/active_support_log_subscriber/active_record.rb +0 -13
  131. data/lib/timber/probes/active_support_log_subscriber.rb +0 -62
  132. data/lib/timber/probes/heroku.rb +0 -30
  133. data/lib/timber/probes/logger.rb +0 -31
  134. data/lib/timber/probes/rack.rb +0 -36
  135. data/lib/timber/probes/server.rb +0 -18
  136. data/spec/timber/bootstrap_spec.rb +0 -31
  137. data/spec/timber/context_snapshot_spec.rb +0 -10
  138. data/spec/timber/context_spec.rb +0 -4
  139. data/spec/timber/contexts/exception_spec.rb +0 -34
  140. data/spec/timber/contexts/organizations/action_controller_spec.rb +0 -49
  141. data/spec/timber/contexts/users/action_controller_spec.rb +0 -65
  142. data/spec/timber/current_line_indexes_spec.rb +0 -40
  143. data/spec/timber/frameworks/rails_spec.rb +0 -9
  144. data/spec/timber/log_devices/heroku_logplex_spec.rb +0 -45
  145. data/spec/timber/log_devices/http/log_truck/delivery_spec.rb +0 -66
  146. data/spec/timber/log_devices/http/log_truck_spec.rb +0 -65
  147. data/spec/timber/log_devices/io/hybrid_hidden_formatter_spec.rb +0 -28
  148. data/spec/timber/log_line_spec.rb +0 -49
  149. data/spec/timber/macros/compactor_spec.rb +0 -19
  150. data/spec/timber/macros/logfmt_encoder_spec.rb +0 -89
  151. data/spec/timber/patterns/to_json_spec.rb +0 -40
  152. data/spec/timber/probes/action_controller_base_spec.rb +0 -43
  153. data/spec/timber/probes/action_controller_log_subscriber/action_controller_spec.rb +0 -35
  154. data/spec/timber/probes/action_controller_log_subscriber/action_view_spec.rb +0 -44
  155. data/spec/timber/probes/action_controller_log_subscriber/active_record_spec.rb +0 -26
  156. data/spec/timber/probes/logger_spec.rb +0 -20
  157. data/spec/timber/probes/rack_spec.rb +0 -26
@@ -1,45 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::LogDevices::HerokuLogplex do
4
- let(:io) { STDOUT }
5
- let(:log_device) { described_class.new }
6
-
7
- describe ".write" do
8
- let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
9
-
10
- before(:each) do
11
- server_context = Timber::CurrentContext.get(Timber::Contexts::Server)
12
- allow(server_context).to receive(:_dt).and_return(time)
13
- end
14
-
15
- it "writes a proper logfmt line" do
16
- expect(io).to receive(:write).with("\e7\e[1;30m@timber.io \e8\e[Kserver.hostname=comp\e8\e[Kuter-name.domain.com\e8\e[K server._dt=2016-09-\e8\e[K01T12:00:00.000000Z \e8\e[Kserver._version=1 se\e8\e[Krver._index=0 _versi\e8\e[Kon=1 _hierarchy=[ser\e8\e[Kver] @original \e8\e[K\e[0mthis is a message\n")
17
- # Notice we do not have dt for the log line since Heroku provides this
18
- log_device.write("this is a message\n")
19
- end
20
-
21
- context "with a heroku context" do
22
- around(:each) do |example|
23
- heroku = Timber::Contexts::Servers::HerokuSpecific.new("web.1")
24
- Timber::CurrentContext.add(heroku) { example.run }
25
- end
26
-
27
- # No need for the heroku context since logplex includes that data by default
28
- it "does not include the heroku context" do
29
- expect(io).to receive(:write).with("\e7\e[1;30m@timber.io \e8\e[Kserver.hostname=comp\e8\e[Kuter-name.domain.com\e8\e[K server._dt=2016-09-\e8\e[K01T12:00:00.000000Z \e8\e[Kserver._version=1 se\e8\e[Krver._index=0 _versi\e8\e[Kon=1 _hierarchy=[ser\e8\e[Kver,server.heroku] @original \e8\e[K\e[0mthis is a message\n")
30
- # Notice we do not have dt for the log line since Heroku provides this
31
- log_device.write("this is a message\n")
32
- end
33
- end
34
-
35
- context "with multiple lines" do |variable|
36
- it "does not include the heroku context" do
37
- expect(io).to receive(:write).with("\e7\e[1;30m@timber.io \e8\e[Kserver.hostname=comp\e8\e[Kuter-name.domain.com\e8\e[K server._dt=2016-09-\e8\e[K01T12:00:00.000000Z \e8\e[Kserver._version=1 se\e8\e[Krver._index=0 _versi\e8\e[Kon=1 _hierarchy=[ser\e8\e[Kver] @original \e8\e[K\e[0mline 1\n")
38
- expect(io).to receive(:write).with("\e7\e[1;30m@timber.io \e8\e[Kserver.hostname=comp\e8\e[Kuter-name.domain.com\e8\e[K server._dt=2016-09-\e8\e[K01T12:00:00.000000Z \e8\e[Kserver._version=1 se\e8\e[Krver._index=1 _versi\e8\e[Kon=1 _hierarchy=[ser\e8\e[Kver] @original \e8\e[K\e[0mline 2\n")
39
- expect(io).to receive(:write).with("\e7\e[1;30m@timber.io \e8\e[Kserver.hostname=comp\e8\e[Kuter-name.domain.com\e8\e[K server._dt=2016-09-\e8\e[K01T12:00:00.000000Z \e8\e[Kserver._version=1 se\e8\e[Krver._index=2 _versi\e8\e[Kon=1 _hierarchy=[ser\e8\e[Kver] @original \e8\e[K\e[0mline 3\n")
40
- # Notice we do not have dt for the log line since Heroku provides this
41
- log_device.write("line 1\nline 2\nline 3\n")
42
- end
43
- end
44
- end
45
- end
@@ -1,66 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::LogDevices::HTTP::LogTruck::Delivery do
4
- describe "#deliver!" do
5
- let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
6
-
7
- before(:each) { ActiveSupport.send(:silence_warnings) { described_class::RETRY_COUNT = 0 } }
8
- after(:each) { ActiveSupport.send(:silence_warnings) { described_class::RETRY_COUNT = 3 } }
9
-
10
- def new_stub
11
- stub_request(:post, "https://timber-odin.herokuapp.com/agent_log_frames").
12
- with(:body => "{\"agent_log_frame\": {\"log_lines\": [{\"dt\":\"2016-09-01T12:00:00.000000Z\",\"message\":\"hello\",\"context\":{\"server\":{\"hostname\":\"computer-name.domain.com\",\"_dt\":\"2016-09-01T12:00:00.000000Z\",\"_version\":1,\"_index\":0},\"_version\":1,\"_hierarchy\":[\"server\"]}}]}}",
13
- :headers => {'Content-Type'=>'application/json'})
14
- end
15
-
16
- around(:each) do |example|
17
- Timecop.freeze(time) { example.run }
18
- end
19
-
20
- before(:each) do
21
- server_context = Timber::CurrentContext.get(Timber::Contexts::Server)
22
- allow(server_context).to receive(:_dt).and_return(time)
23
- end
24
-
25
- let(:log_lines) { [Timber::LogLine.new("hello")] }
26
- let(:delivery) { described_class.new(Timber::Config.application_key, log_lines) }
27
- let(:stub) { new_stub }
28
-
29
- before(:each) { stub }
30
-
31
- it "should delivery successfully" do
32
- delivery.deliver!
33
- expect(stub).to have_been_requested
34
- end
35
-
36
- context "timeout error" do
37
- let(:stub) {
38
- new_stub.to_timeout
39
- }
40
-
41
- it "should raise an error" do
42
- expect { delivery.deliver! }.to raise_error(Timber::LogDevices::HTTP::LogTruck::Delivery::DeliveryError)
43
- end
44
- end
45
-
46
- context "random error" do
47
- let(:stub) {
48
- new_stub.to_raise(StandardError.new("some error"))
49
- }
50
-
51
- it "should raise an error" do
52
- expect { delivery.deliver! }.to raise_error(Timber::LogDevices::HTTP::LogTruck::Delivery::DeliveryError)
53
- end
54
- end
55
-
56
- context "internal server error" do
57
- let(:stub) {
58
- new_stub.to_return(status: [500, "Internal Server Error"])
59
- }
60
-
61
- it "should raise an error" do
62
- expect { delivery.deliver! }.to raise_error(Timber::LogDevices::HTTP::LogTruck::Delivery::DeliveryError)
63
- end
64
- end
65
- end
66
- end
@@ -1,65 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::LogDevices::HTTP::LogTruck do
4
- describe ".start!" do
5
- it "spawns a new thread" do
6
- expect(Thread).to receive(:new).once
7
- described_class.start!
8
- end
9
-
10
- it "delivers" do
11
- expect(described_class).to receive(:deliver).once
12
- described_class.start! do |thread|
13
- thread.kill
14
- end.join
15
- end
16
- end
17
-
18
- describe ".deliver" do
19
- let(:log_pile) { Timber::LogDevices::HTTP::LogPile.get(Timber::Config.application_key) }
20
-
21
- it "doesn't deliver because there is nothing to deliver" do
22
- expect(log_pile).to_not receive(:deliver)
23
- described_class.deliver
24
- end
25
-
26
- context "with a log pile" do
27
- before(:each) do
28
- log_line = Timber::LogLine.new("this is a log line")
29
- log_pile.drop(log_line)
30
- end
31
-
32
- it "delivers once and empties the log pile" do
33
- expect(log_pile.size).to eq(1)
34
- expect_any_instance_of(described_class).to receive(:deliver!).once
35
- described_class.deliver
36
- expect(log_pile.size).to eq(0)
37
- end
38
- end
39
- end
40
-
41
- describe "#initialize" do
42
- let(:log_lines) { [] }
43
- let(:log_truck) { described_class.new(Timber::Config.application_key, log_lines) }
44
- subject { log_truck }
45
-
46
- it "should raise an exception" do
47
- expect { subject }.to raise_exception(Timber::LogDevices::HTTP::LogTruck::NoPayloadError)
48
- end
49
-
50
- context "with log lines" do
51
- let(:log_lines) { [Timber::LogLine.new("hello")] }
52
- its(:log_lines) { should eq(log_lines) }
53
- end
54
- end
55
-
56
- describe "#deliver!" do
57
- let(:log_lines) { [Timber::LogLine.new("hello")] }
58
- let(:log_truck) { described_class.new(Timber::Config.application_key, log_lines) }
59
-
60
- it "should delivery successfully" do
61
- expect_any_instance_of(Timber::LogDevices::HTTP::LogTruck::Delivery).to receive(:deliver!)
62
- log_truck.deliver!
63
- end
64
- end
65
- end
@@ -1,28 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::LogDevices::IO::HybridHiddenFormatter do
4
- describe ".format" do
5
- let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
6
- let(:formatter) { described_class.new }
7
- let(:message) { "a message" }
8
- let(:log_line) { Timber::LogLine.new(message) }
9
- subject { formatter.format(log_line) }
10
-
11
- before(:each) do
12
- server_context = Timber::CurrentContext.get(Timber::Contexts::Server)
13
- allow(server_context).to receive(:_dt).and_return(time)
14
- end
15
-
16
- it { should eq("\e7\e[1;30m@timber.io \e8\e[Kserver.hostname=comp\e8\e[Kuter-name.domain.com\e8\e[K server._dt=2016-09-\e8\e[K01T12:00:00.000000Z \e8\e[Kserver._version=1 se\e8\e[Krver._index=0 _versi\e8\e[Kon=1 _hierarchy=[ser\e8\e[Kver] @original \e8\e[K\e[0ma message") }
17
-
18
- context "with a slash" do
19
- let(:message) { "this is a long message that exceeds the step size".insert(described_class::CLEAR_STEP_SIZE - 1, "\\") }
20
-
21
- before(:each) do
22
- allow(formatter).to receive(:encoded_context).and_return(message)
23
- end
24
-
25
- it { should eq("\e7\e[1;30m@timber.io \e8\e[Kthis is a long mess\\a\e8\e[Kge that exceeds the \e8\e[Kstep size @original \e8\e[K\e[0mthis is a long mess\\a\e8\e[Kge that exceeds the \e8\e[Kstep size") }
26
- end
27
- end
28
- end
@@ -1,49 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::LogLine do
4
- let(:message) { "this is a message" }
5
- let(:log_line) { described_class.new(message) }
6
-
7
- around(:each) do |example|
8
- heroku = Timber::Contexts::Servers::HerokuSpecific.new("web.1")
9
- Timber::CurrentContext.add(heroku) { example.run }
10
- end
11
-
12
- describe "#initialize" do
13
- subject { log_line }
14
-
15
- its(:dt) { should_not be_nil }
16
- its(:message) { should equal(message) }
17
-
18
- context "non string" do
19
- let(:message) { :"this is a message" }
20
- its(:message) { should eq(message.to_s) }
21
- end
22
-
23
- context "exceeds bytesize limit" do
24
- let(:limit) { Timber::APISettings::MESSAGE_BYTE_SIZE_MAX }
25
- let(:message) { (1..(limit + 1)).collect { "A" }.join }
26
- its(:message) { should_not eq(message) }
27
- its(:message) { should eq(message.byteslice(0, Timber::APISettings::MESSAGE_BYTE_SIZE_MAX)) }
28
- end
29
-
30
- it "notifies CurrentLineIndexes" do
31
- expect(Timber::CurrentLineIndexes).to receive(:log_line_added).once
32
- subject
33
- end
34
- end
35
-
36
- describe "#to_json" do
37
- # Note: very important that we keep the iso8601 format. Otherwise the Timber API
38
- # will recognized the date as invalid.
39
- let(:as_json) do
40
- {
41
- dt: log_line.dt.iso8601(6),
42
- message: log_line.message,
43
- }.merge(log_line.context_snapshot.as_json)
44
- end
45
- let(:json) { as_json.to_json }
46
- subject { log_line.to_json }
47
- it { should eq(json) }
48
- end
49
- end
@@ -1,19 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::Macros::Compactor do
4
- describe ".compact" do
5
- let(:hash) { {} }
6
- subject { described_class.compact(hash) }
7
- it { should eq({}) }
8
-
9
- context "nested" do
10
- let(:hash) { {:whatever => {:nested => nil}} }
11
- it { should eq({}) }
12
- end
13
-
14
- context "nested with other values" do
15
- let(:hash) { {:whatever => {:nested => nil, :with_val => 1}, :another => 1} }
16
- it { should eq({:whatever => {:with_val => 1}, :another => 1}) }
17
- end
18
- end
19
- end
@@ -1,89 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::Macros::LogfmtEncoder do
4
- describe ".encode" do
5
- subject { described_class.encode(target) }
6
-
7
- context "nil" do
8
- let(:target) { nil }
9
- it "should raise" do
10
- expect { subject }.to raise_error(ArgumentError)
11
- end
12
- end
13
-
14
- context "blank hash" do
15
- let(:target) { {} }
16
- it { should eq("") }
17
- end
18
-
19
- context "simple hash" do
20
- let(:target) { {"key" => "value"} }
21
- it { should eq("key=value") }
22
- end
23
-
24
- context "with space in value" do
25
- let(:target) { {"key" => "this is a value"} }
26
- it { should eq("key=\"this is a value\"") }
27
- end
28
-
29
- context "with quote in value" do
30
- let(:target) { {"key" => "value\"another"} }
31
- it { should eq("key=\"value\\\"another\"") }
32
- end
33
-
34
- context "with a space in the key" do
35
- let(:target) { {"this is a key" => "value"} }
36
- it { should eq("\"this is a key\"=value") }
37
- end
38
-
39
- context "with a . in the key" do
40
- let(:target) { {"this.is.a.key" => "value"} }
41
- it { should eq("\"this.is.a.key\"=value") }
42
- end
43
-
44
- context "with a nested hash" do
45
- let(:target) { {"key" => {"sub_key" => "value"}} }
46
- it { should eq("key.sub_key=value") }
47
- end
48
-
49
- context "with a nested hash and space in the key" do
50
- let(:target) { {"key" => {"sub key" => "value"}} }
51
- it { should eq("key.\"sub key\"=value") }
52
- end
53
-
54
- context "with a nested hash and . in the key" do
55
- let(:target) { {"key" => {"sub.key" => "value"}} }
56
- it { should eq("key.\"sub.key\"=value") }
57
- end
58
-
59
- context "with an integer value" do
60
- let(:target) { {"key" => 1} }
61
- it { should eq("key=1") }
62
- end
63
-
64
- context "with a float value" do
65
- let(:target) { {"key" => 1.23} }
66
- it { should eq("key=1.23") }
67
- end
68
-
69
- context "with a true value" do
70
- let(:target) { {"key" => true} }
71
- it { should eq("key=true") }
72
- end
73
-
74
- context "with a false value" do
75
- let(:target) { {"key" => false} }
76
- it { should eq("key=false") }
77
- end
78
-
79
- context "with an array value" do
80
- let(:target) { {"key" => ["this is a value",2,3]} }
81
- it { should eq("key=[\"this is a value\",2,3]") }
82
- end
83
-
84
- context "with an array value that has a ," do
85
- let(:target) { {"key" => ["this,is a value",2,3]} }
86
- it { should eq("key=[\"this,is a value\",2,3]") }
87
- end
88
- end
89
- end
@@ -1,40 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::Patterns::ToJSON do
4
- class TestJSON
5
- include Timber::Patterns::ToJSON
6
-
7
- attr_reader :json_payload
8
-
9
- def initialize(json_payload)
10
- @json_payload = json_payload
11
- end
12
- end
13
-
14
- describe ".as_json" do
15
- let(:hash) { {} }
16
- let(:target) { TestJSON.new(hash) }
17
- subject { target.as_json }
18
- it { should eq({}) }
19
-
20
- context "with a value" do
21
- let(:hash) { {:test => 1} }
22
- it { should eq({:test => 1}) }
23
- end
24
-
25
- context "with a nil value" do
26
- let(:hash) { {:test => nil} }
27
- it { should eq({}) }
28
- end
29
-
30
- context "with an empty array" do
31
- let(:hash) { {:test => []} }
32
- it { should eq({}) }
33
- end
34
-
35
- context "with an empty hash" do
36
- let(:hash) { {:test => {}} }
37
- it { should eq({}) }
38
- end
39
- end
40
- end
@@ -1,43 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::Probes::ActionControllerBase do
4
- describe described_class::InstanceMethods do
5
- before(:each) do
6
- class PagesPlainController < ActionController::Base
7
- layout nil
8
-
9
- def index
10
- render json: {}
11
- end
12
-
13
- def method_for_action(action_name)
14
- action_name
15
- end
16
- end
17
-
18
- ::RailsApp.routes.draw do
19
- get 'pages_plain' => 'pages_plain#index'
20
- end
21
- end
22
-
23
- after(:each) do
24
- Object.send(:remove_const, :PagesPlainController)
25
- end
26
-
27
- let(:logger_context_class) { Timber::Contexts::Logger }
28
- let(:rack_request_context_class) { Timber::Contexts::HTTPRequests::Rack }
29
- let(:request_context_class) { Timber::Contexts::HTTPRequests::ActionControllerSpecific }
30
- let(:organization_context_class) { Timber::Contexts::Organizations::ActionController }
31
- let(:user_context_class) { Timber::Contexts::Users::ActionController }
32
- let(:response_context_class) { Timber::Contexts::HTTPResponses::ActionController }
33
-
34
- describe "#process" do
35
- it "should set the context" do
36
- allow(Timber::CurrentContext).to receive(:add).with(kind_of(logger_context_class))
37
- expect(Timber::CurrentContext).to receive(:add).with(kind_of(rack_request_context_class)).and_yield.once
38
- expect(Timber::CurrentContext).to receive(:add).with(kind_of(request_context_class), kind_of(organization_context_class), kind_of(user_context_class), kind_of(response_context_class)).and_yield.once
39
- dispatch_rails_request("/pages_plain")
40
- end
41
- end
42
- end
43
- end
@@ -1,35 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::Probes::ActiveSupportLogSubscriber::ActionController do
4
- before(:each) do
5
- class PagesController < ActionController::Base
6
- layout nil
7
-
8
- def index
9
- response.headers['Content-Length'] = "500"
10
- render json: {}
11
- end
12
-
13
- def method_for_action(action_name)
14
- action_name
15
- end
16
- end
17
-
18
- ::RailsApp.routes.draw do
19
- get 'pages' => 'pages#index'
20
- end
21
- end
22
-
23
- after(:each) do
24
- Object.send(:remove_const, :PagesController)
25
- end
26
-
27
- let(:response_context_class) { Timber::Contexts::HTTPResponses::ActionController }
28
-
29
- describe "#process_action" do
30
- it "should set the context" do
31
- expect_any_instance_of(response_context_class).to receive(:event=).with(kind_of(ActiveSupport::Notifications::Event)).once
32
- dispatch_rails_request("/pages")
33
- end
34
- end
35
- end
@@ -1,44 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::Probes::ActiveSupportLogSubscriber::ActionView do
4
- before(:each) do
5
- class UsersController < ActionController::Base
6
- layout nil
7
-
8
- def index
9
- render template: "template"
10
- end
11
-
12
- def method_for_action(action_name)
13
- action_name
14
- end
15
- end
16
-
17
- ::RailsApp.routes.draw do
18
- get 'users' => 'users#index'
19
- end
20
- end
21
-
22
- after(:each) do
23
- Object.send(:remove_const, :UsersController)
24
- end
25
-
26
- let(:logger_context_class) { Timber::Contexts::Logger }
27
- let(:rack_request_context_class) { Timber::Contexts::HTTPRequests::Rack }
28
- let(:request_context_class) { Timber::Contexts::HTTPRequests::ActionControllerSpecific }
29
- let(:organization_context_class) { Timber::Contexts::Organizations::ActionController }
30
- let(:user_context_class) { Timber::Contexts::Users::ActionController }
31
- let(:response_context_class) { Timber::Contexts::HTTPResponses::ActionController }
32
- let(:action_view_context_class) { Timber::Contexts::TemplateRenders::ActionView }
33
- let(:action_view_specific_context_class) { Timber::Contexts::TemplateRenders::ActionViewSpecific }
34
-
35
- describe "#process_action" do
36
- it "should set the context" do
37
- allow(Timber::CurrentContext).to receive(:add).with(kind_of(logger_context_class))
38
- expect(Timber::CurrentContext).to receive(:add).with(kind_of(rack_request_context_class)).and_yield.once
39
- expect(Timber::CurrentContext).to receive(:add).with(kind_of(request_context_class), kind_of(organization_context_class), kind_of(user_context_class), kind_of(response_context_class)).and_yield.once
40
- expect(Timber::CurrentContext).to receive(:add).with(kind_of(action_view_context_class), kind_of(action_view_specific_context_class)).and_yield.once
41
- dispatch_rails_request("/users")
42
- end
43
- end
44
- end
@@ -1,26 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::Probes::ActiveSupportLogSubscriber::ActiveRecord do
4
- before(:each) { Timber::Probes::ActiveSupportLogSubscriber.insert! }
5
-
6
- let(:logger_context_class) { Timber::Contexts::Logger }
7
- let(:active_record_context_class) { Timber::Contexts::SQLQueries::ActiveRecord }
8
- let(:active_record_specific_context_class) { Timber::Contexts::SQLQueries::ActiveRecordSpecific }
9
-
10
- describe "#sql" do
11
- context "log level debug" do
12
- before(:each) do
13
- @old_level = ::ActiveRecord::Base.logger.level
14
- ::ActiveRecord::Base.logger.level = Logger::DEBUG
15
- end
16
-
17
- after(:each) { ::ActiveRecord::Base.logger.level = @old_level }
18
-
19
- it "should set the context" do
20
- expect(Timber::CurrentContext).to receive(:add).with(kind_of(logger_context_class)).and_yield.once
21
- expect(Timber::CurrentContext).to receive(:add).with(kind_of(active_record_context_class), kind_of(active_record_specific_context_class)).and_yield.once
22
- ActiveRecord::Base.connection.execute("select * from users")
23
- end
24
- end
25
- end
26
- end
@@ -1,20 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::Probes::Logger do
4
- describe described_class::InstanceMethods do
5
- describe ".add" do
6
- let(:logger) { ::Logger.new(nil) }
7
- let(:context_class) { Timber::Contexts::Logger }
8
-
9
- it "should set the context" do
10
- expect(Timber::CurrentContext).to receive(:add).with(kind_of(context_class)).and_yield.once
11
- logger.info("test")
12
- end
13
-
14
- it "should ignore Config.logger" do
15
- expect(Timber::CurrentContext).to_not receive(:add).with(kind_of(context_class))
16
- Timber::Config.logger.info("text")
17
- end
18
- end
19
- end
20
- end
@@ -1,26 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Timber::Probes::Rack do
4
- describe described_class::Middleware do
5
- describe ".call" do
6
- let(:app) do
7
- Rack::Builder.new do
8
- use Timber::Probes::Rack::Middleware
9
- run lambda { |env|
10
- [200, {'Content-Type' => 'text/plain'}, ['hello world']]
11
- }
12
- end
13
- end
14
- let(:context_class) { Timber::Contexts::HTTPRequests::Rack }
15
-
16
- def request
17
- Rack::MockRequest.new(app).get('/')
18
- end
19
-
20
- it "should set the context" do
21
- expect(Timber::CurrentContext).to receive(:add).with(kind_of(context_class)).and_yield.once
22
- request
23
- end
24
- end
25
- end
26
- end