timber 2.6.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +8 -38
- data/CHANGELOG.md +9 -0
- data/README.md +30 -284
- data/Rakefile +78 -0
- data/lib/timber.rb +6 -6
- data/lib/timber/config.rb +1 -83
- data/lib/timber/config/integrations.rb +1 -47
- data/lib/timber/context.rb +3 -24
- data/lib/timber/contexts.rb +2 -30
- data/lib/timber/contexts/http.rb +16 -36
- data/lib/timber/contexts/release.rb +12 -23
- data/lib/timber/contexts/runtime.rb +9 -36
- data/lib/timber/contexts/session.rb +8 -21
- data/lib/timber/contexts/system.rb +9 -16
- data/lib/timber/contexts/user.rb +13 -33
- data/lib/timber/current_context.rb +16 -78
- data/lib/timber/event.rb +12 -9
- data/lib/timber/events.rb +1 -33
- data/lib/timber/events/controller_call.rb +20 -31
- data/lib/timber/events/error.rb +18 -26
- data/lib/timber/events/exception.rb +1 -0
- data/lib/timber/events/sql_query.rb +14 -24
- data/lib/timber/events/template_render.rb +13 -24
- data/lib/timber/integration.rb +1 -1
- data/lib/timber/integrator.rb +1 -1
- data/lib/timber/log_devices/http.rb +98 -19
- data/lib/timber/log_entry.rb +6 -24
- data/lib/timber/logger.rb +5 -14
- data/lib/timber/util.rb +1 -6
- data/lib/timber/util/non_nil_hash_builder.rb +3 -1
- data/lib/timber/version.rb +1 -1
- data/spec/README.md +2 -8
- data/spec/spec_helper.rb +0 -7
- data/spec/support/timber.rb +1 -3
- data/spec/timber/current_context_spec.rb +12 -50
- data/spec/timber/events/controller_call_spec.rb +4 -4
- data/spec/timber/events/error_spec.rb +4 -9
- data/spec/timber/log_devices/http_spec.rb +26 -2
- data/spec/timber/log_entry_spec.rb +12 -6
- data/spec/timber/logger_spec.rb +27 -68
- data/timber.gemspec +1 -1
- metadata +5 -139
- data/gemfiles/rails-3.0.gemfile +0 -5
- data/gemfiles/rails-3.1.gemfile +0 -5
- data/gemfiles/rails-3.2.gemfile +0 -5
- data/gemfiles/rails-4.0.gemfile +0 -9
- data/gemfiles/rails-4.1.gemfile +0 -9
- data/gemfiles/rails-4.2.gemfile +0 -9
- data/gemfiles/rails-5.0.gemfile +0 -9
- data/gemfiles/rails-5.1.gemfile +0 -9
- data/gemfiles/rails-edge.gemfile +0 -7
- data/lib/timber/cli.rb +0 -60
- data/lib/timber/cli/api.rb +0 -183
- data/lib/timber/cli/api/application.rb +0 -34
- data/lib/timber/cli/config_file.rb +0 -71
- data/lib/timber/cli/file_helper.rb +0 -53
- data/lib/timber/cli/installer.rb +0 -70
- data/lib/timber/cli/installers.rb +0 -102
- data/lib/timber/cli/installers/config_file.rb +0 -51
- data/lib/timber/cli/installers/other.rb +0 -59
- data/lib/timber/cli/installers/rails.rb +0 -225
- data/lib/timber/cli/installers/root.rb +0 -116
- data/lib/timber/cli/io.rb +0 -100
- data/lib/timber/cli/io/ansi.rb +0 -22
- data/lib/timber/cli/io/messages.rb +0 -198
- data/lib/timber/cli/os_helper.rb +0 -74
- data/lib/timber/config/integrations/rack.rb +0 -74
- data/lib/timber/contexts/custom.rb +0 -44
- data/lib/timber/contexts/organization.rb +0 -48
- data/lib/timber/events/custom.rb +0 -53
- data/lib/timber/events/http_request.rb +0 -71
- data/lib/timber/events/http_response.rb +0 -81
- data/lib/timber/frameworks.rb +0 -19
- data/lib/timber/frameworks/rails.rb +0 -27
- data/lib/timber/integrations.rb +0 -29
- data/lib/timber/integrations/action_controller.rb +0 -18
- data/lib/timber/integrations/action_controller/log_subscriber.rb +0 -27
- data/lib/timber/integrations/action_controller/log_subscriber/timber_log_subscriber.rb +0 -46
- data/lib/timber/integrations/action_dispatch.rb +0 -23
- data/lib/timber/integrations/action_dispatch/debug_exceptions.rb +0 -53
- data/lib/timber/integrations/action_view.rb +0 -18
- data/lib/timber/integrations/action_view/log_subscriber.rb +0 -27
- data/lib/timber/integrations/action_view/log_subscriber/timber_log_subscriber.rb +0 -83
- data/lib/timber/integrations/active_record.rb +0 -18
- data/lib/timber/integrations/active_record/log_subscriber.rb +0 -26
- data/lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb +0 -53
- data/lib/timber/integrations/rack.rb +0 -27
- data/lib/timber/integrations/rack/error_event.rb +0 -64
- data/lib/timber/integrations/rack/http_context.rb +0 -27
- data/lib/timber/integrations/rack/http_events.rb +0 -210
- data/lib/timber/integrations/rack/middleware.rb +0 -28
- data/lib/timber/integrations/rack/session_context.rb +0 -65
- data/lib/timber/integrations/rack/user_context.rb +0 -135
- data/lib/timber/integrations/rails.rb +0 -22
- data/lib/timber/integrations/rails/rack_logger.rb +0 -60
- data/lib/timber/overrides.rb +0 -12
- data/lib/timber/overrides/active_support_3_tagged_logging.rb +0 -111
- data/lib/timber/overrides/active_support_buffered_logger.rb +0 -22
- data/lib/timber/overrides/active_support_tagged_logging.rb +0 -66
- data/lib/timber/overrides/lograge.rb +0 -18
- data/lib/timber/overrides/rails_stdout_logging.rb +0 -21
- data/lib/timber/util/active_support_log_subscriber.rb +0 -37
- data/lib/timber/util/attribute_normalizer.rb +0 -89
- data/lib/timber/util/hash.rb +0 -90
- data/lib/timber/util/request.rb +0 -72
- data/lib/timber/util/struct.rb +0 -16
- data/spec/rails/tagged_logging_spec.rb +0 -44
- data/spec/support/action_controller.rb +0 -8
- data/spec/support/active_record.rb +0 -32
- data/spec/support/rails.rb +0 -67
- data/spec/support/rails/templates/_partial.html +0 -1
- data/spec/support/rails/templates/template.html +0 -1
- data/spec/timber/cli/config_file_spec.rb +0 -26
- data/spec/timber/cli/installers/config_file_spec.rb +0 -36
- data/spec/timber/cli/installers/other_spec.rb +0 -49
- data/spec/timber/cli/installers/rails_spec.rb +0 -364
- data/spec/timber/cli/installers/root_spec.rb +0 -73
- data/spec/timber/config_spec.rb +0 -28
- data/spec/timber/contexts/custom_spec.rb +0 -11
- data/spec/timber/contexts/organization_spec.rb +0 -11
- data/spec/timber/contexts/runtime_spec.rb +0 -11
- data/spec/timber/contexts/system_spec.rb +0 -11
- data/spec/timber/contexts/user_spec.rb +0 -11
- data/spec/timber/contexts_spec.rb +0 -49
- data/spec/timber/event_spec.rb +0 -10
- data/spec/timber/events/custom_spec.rb +0 -36
- data/spec/timber/events/http_request_spec.rb +0 -32
- data/spec/timber/events/http_response_spec.rb +0 -12
- data/spec/timber/events_spec.rb +0 -55
- data/spec/timber/integrations/action_controller/log_subscriber_spec.rb +0 -55
- data/spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb +0 -53
- data/spec/timber/integrations/action_view/log_subscriber_spec.rb +0 -115
- data/spec/timber/integrations/active_record/log_subscriber_spec.rb +0 -46
- data/spec/timber/integrations/rack/error_event_spec.rb +0 -63
- data/spec/timber/integrations/rack/http_context_spec.rb +0 -60
- data/spec/timber/integrations/rack/http_events_spec.rb +0 -101
- data/spec/timber/integrations/rack/session_context_spec.rb +0 -62
- data/spec/timber/integrations/rails/rack_logger_spec.rb +0 -58
- data/spec/timber/util/attribute_normalizer_spec.rb +0 -90
- data/spec/timber/util/hash_spec.rb +0 -30
- data/spec/timber/util/request_spec.rb +0 -10
data/lib/timber/util.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
|
-
require "timber/util/active_support_log_subscriber"
|
2
|
-
require "timber/util/attribute_normalizer"
|
3
|
-
require "timber/util/hash"
|
4
1
|
require "timber/util/non_nil_hash_builder"
|
5
|
-
require "timber/util/request"
|
6
|
-
require "timber/util/struct"
|
7
2
|
|
8
3
|
module Timber
|
9
4
|
# @private
|
10
5
|
module Util
|
11
6
|
end
|
12
|
-
end
|
7
|
+
end
|
data/lib/timber/version.rb
CHANGED
data/spec/README.md
CHANGED
@@ -6,14 +6,8 @@ To get started:
|
|
6
6
|
bundle install
|
7
7
|
```
|
8
8
|
|
9
|
-
Be sure to install specific Gemfile dependencies:
|
10
|
-
|
11
|
-
```
|
12
|
-
BUNDLE_GEMFILE=gemfiles/rails-4.2.gemfile bundle install
|
13
|
-
```
|
14
|
-
|
15
9
|
You can run tests like this:
|
16
10
|
|
17
11
|
```shell
|
18
|
-
|
19
|
-
```
|
12
|
+
bundle exec rspec
|
13
|
+
```
|
data/spec/spec_helper.rb
CHANGED
@@ -13,13 +13,6 @@ require File.join(File.dirname(__FILE__), 'support', 'timecop')
|
|
13
13
|
require File.join(File.dirname(__FILE__), 'support', 'webmock')
|
14
14
|
require File.join(File.dirname(__FILE__), 'support', 'timber')
|
15
15
|
|
16
|
-
# Load framework files after we've setup everything
|
17
|
-
if !ENV["RAILS_23"]
|
18
|
-
require File.join(File.dirname(__FILE__), 'support', 'rails')
|
19
|
-
require File.join(File.dirname(__FILE__), 'support', 'action_controller')
|
20
|
-
require File.join(File.dirname(__FILE__), 'support', 'active_record')
|
21
|
-
end
|
22
|
-
|
23
16
|
RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = 5_000
|
24
17
|
|
25
18
|
RSpec.configure do |config|
|
data/spec/support/timber.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Timber::CurrentContext
|
3
|
+
describe Timber::CurrentContext do
|
4
4
|
describe ".initialize" do
|
5
5
|
it "should not set the release context" do
|
6
6
|
context = described_class.send(:new)
|
@@ -10,13 +10,13 @@ describe Timber::CurrentContext, :rails_23 => true do
|
|
10
10
|
it "should set the system context" do
|
11
11
|
context = described_class.send(:new)
|
12
12
|
system_content = context.fetch(:system)
|
13
|
-
expect(system_content[:hostname]).
|
13
|
+
expect(system_content[:hostname]).to_not be_nil
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should set the runtime context" do
|
17
17
|
context = described_class.send(:new)
|
18
18
|
runtime_context = context.fetch(:runtime)
|
19
|
-
expect(runtime_context[:
|
19
|
+
expect(runtime_context[:thread_id]).to_not be_nil
|
20
20
|
end
|
21
21
|
|
22
22
|
context "with Heroku dyno metadata" do
|
@@ -40,7 +40,7 @@ describe Timber::CurrentContext, :rails_23 => true do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
context "with
|
43
|
+
context "with generic env vars" do
|
44
44
|
around(:each) do |example|
|
45
45
|
ENV['RELEASE_COMMIT'] = "2c3a0b24069af49b3de35b8e8c26765c1dba9ff0"
|
46
46
|
ENV['RELEASE_CREATED_AT'] = "2015-04-02T18:00:42Z"
|
@@ -68,63 +68,25 @@ describe Timber::CurrentContext, :rails_23 => true do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should add the context" do
|
71
|
-
expect(described_class.instance.send(:hash)[:
|
71
|
+
expect(described_class.instance.send(:hash)[:build]).to be_nil
|
72
72
|
|
73
73
|
described_class.add({build: {version: "1.0.0"}})
|
74
|
-
expect(described_class.instance.send(:hash)[:
|
74
|
+
expect(described_class.instance.send(:hash)[:build]).to eq({:version=>"1.0.0"})
|
75
75
|
|
76
76
|
described_class.add({testing: {key: "value"}})
|
77
|
-
expect(described_class.instance.send(:hash)[:
|
77
|
+
expect(described_class.instance.send(:hash)[:build]).to eq({:version=>"1.0.0"})
|
78
|
+
expect(described_class.instance.send(:hash)[:testing]).to eq({:key=>"value"})
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
82
|
describe ".remove" do
|
82
|
-
it "should remove the context by object" do
|
83
|
-
context = {:build=>{:version=>"1.0.0"}}
|
84
|
-
described_class.add(context)
|
85
|
-
expect(described_class.instance.send(:hash)[:custom]).to eq(context)
|
86
|
-
|
87
|
-
described_class.remove(context)
|
88
|
-
expect(described_class.instance.send(:hash)[:custom]).to be_nil
|
89
|
-
end
|
90
|
-
|
91
83
|
it "should remove context by key" do
|
92
84
|
context = {:build=>{:version=>"1.0.0"}}
|
93
85
|
described_class.add(context)
|
94
|
-
expect(described_class.instance.send(:hash)[:
|
95
|
-
|
96
|
-
described_class.remove(:custom)
|
97
|
-
expect(described_class.instance.send(:hash)[:custom]).to be_nil
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe ".snapshot" do
|
102
|
-
it "shoud properly snapshot custom contexts" do
|
103
|
-
snapshot = nil
|
104
|
-
|
105
|
-
described_class.with({build: {version: "1.0.0"}}) do
|
106
|
-
snapshot = described_class.instance.snapshot
|
107
|
-
end
|
108
|
-
|
109
|
-
expect(snapshot[:custom]).to eq({:build=>{:version=>"1.0.0"}})
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe ".with" do
|
114
|
-
it "should merge the context and cleanup on block exit" do
|
115
|
-
expect(described_class.instance.send(:hash)[:custom]).to be_nil
|
116
|
-
|
117
|
-
described_class.with({build: {version: "1.0.0"}}) do
|
118
|
-
expect(described_class.instance.send(:hash)[:custom]).to eq({:build=>{:version=>"1.0.0"}})
|
119
|
-
|
120
|
-
described_class.with({testing: {key: "value"}}) do
|
121
|
-
expect(described_class.instance.send(:hash)[:custom]).to eq({:build=>{:version=>"1.0.0"}, :testing=>{:key=>"value"}})
|
122
|
-
end
|
123
|
-
|
124
|
-
expect(described_class.instance.send(:hash)[:custom]).to eq({:build=>{:version=>"1.0.0"}})
|
125
|
-
end
|
86
|
+
expect(described_class.instance.send(:hash)[:build]).to eq({:version=>"1.0.0"})
|
126
87
|
|
127
|
-
|
88
|
+
described_class.remove(:build)
|
89
|
+
expect(described_class.instance.send(:hash)[:build]).to be_nil
|
128
90
|
end
|
129
91
|
end
|
130
|
-
end
|
92
|
+
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Timber::Events::ControllerCall
|
5
|
+
describe Timber::Events::ControllerCall do
|
6
6
|
describe ".initialize" do
|
7
7
|
it "sanitizes the password param" do
|
8
|
-
event = described_class.new(controller: 'controller', action: 'action', params: {password: 'password'})
|
9
|
-
expect(event.params).to eq({'password' => '[sanitized]'})
|
8
|
+
# event = described_class.new(controller: 'controller', action: 'action', params: {password: 'password'})
|
9
|
+
# expect(event.params).to eq({'password' => '[sanitized]'})
|
10
10
|
end
|
11
11
|
end
|
12
|
-
end
|
12
|
+
end
|
@@ -1,20 +1,15 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Timber::Events::Error
|
3
|
+
describe Timber::Events::Error do
|
4
4
|
describe "#to_hash" do
|
5
5
|
it "should jsonify the stacktrace" do
|
6
6
|
backtrace = [
|
7
7
|
"/path/to/file1.rb:26:in `function1'",
|
8
8
|
"path/to/file2.rb:86:in `function2'"
|
9
9
|
]
|
10
|
-
exception_event = described_class.new(name: "RuntimeError", error_message: "Boom", backtrace: backtrace)
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
:message => "Boom",
|
15
|
-
:backtrace_json => "[\"/path/to/file1.rb:26:in `function1'\",\"path/to/file2.rb:86:in `function2'\"]"
|
16
|
-
}
|
17
|
-
expect(exception_event.to_hash).to eq(expected_hash)
|
11
|
+
exception_event = described_class.new(name: "RuntimeError", error_message: "Boom", backtrace: backtrace)
|
12
|
+
expect(exception_event.backtrace_json).to eq("[\"/path/to/file1.rb:26:in `function1'\",\"path/to/file2.rb:86:in `function2'\"]")
|
18
13
|
end
|
19
14
|
end
|
20
|
-
end
|
15
|
+
end
|
@@ -102,7 +102,7 @@ describe Timber::LogDevices::HTTP do
|
|
102
102
|
request_queue = http.instance_variable_get(:@request_queue)
|
103
103
|
request_attempt = request_queue.deq
|
104
104
|
expect(request_attempt.request).to be_kind_of(Net::HTTP::Post)
|
105
|
-
expect(request_attempt.request.body).to start_with("\x92\
|
105
|
+
expect(request_attempt.request.body).to start_with("\x92\x83\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT"))
|
106
106
|
|
107
107
|
message_queue = http.instance_variable_get(:@msg_queue)
|
108
108
|
expect(message_queue.size).to eq(0)
|
@@ -125,9 +125,33 @@ describe Timber::LogDevices::HTTP do
|
|
125
125
|
let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
|
126
126
|
|
127
127
|
it "should deliver requests on an interval" do
|
128
|
+
stub = stub_request(:post, "https://logs.timber.io/sources/MY_SOURCE/frames").
|
129
|
+
with(
|
130
|
+
:body => start_with("\x92\x83\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT")),
|
131
|
+
:headers => {
|
132
|
+
'Authorization' => 'Bearer MYKEY',
|
133
|
+
'Content-Type' => 'application/msgpack',
|
134
|
+
'User-Agent' => "Timber Ruby/#{Timber::VERSION} (HTTP)"
|
135
|
+
}
|
136
|
+
).
|
137
|
+
to_return(:status => 200, :body => "", :headers => {})
|
138
|
+
|
139
|
+
http = described_class.new("MYKEY", "MY_SOURCE", flush_interval: 0.1)
|
140
|
+
log_entry1 = Timber::LogEntry.new("INFO", time, nil, "test log message 1", nil, nil)
|
141
|
+
http.write(log_entry1)
|
142
|
+
log_entry2 = Timber::LogEntry.new("INFO", time, nil, "test log message 2", nil, nil)
|
143
|
+
http.write(log_entry2)
|
144
|
+
sleep 2
|
145
|
+
|
146
|
+
expect(stub).to have_been_requested.times(1)
|
147
|
+
|
148
|
+
http.close
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should support legacy API keys" do
|
128
152
|
stub = stub_request(:post, "https://logs.timber.io/frames").
|
129
153
|
with(
|
130
|
-
:body => start_with("\x92\
|
154
|
+
:body => start_with("\x92\x83\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1".force_encoding("ASCII-8BIT")),
|
131
155
|
:headers => {
|
132
156
|
'Authorization' => 'Basic TVlLRVk=',
|
133
157
|
'Content-Type' => 'application/msgpack',
|
@@ -1,16 +1,22 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Timber::LogEntry
|
3
|
+
describe Timber::LogEntry do
|
4
4
|
let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
|
5
5
|
|
6
6
|
describe "#to_msgpack" do
|
7
7
|
it "should encode properly with an event and context" do
|
8
|
-
event =
|
9
|
-
|
10
|
-
|
8
|
+
event = {
|
9
|
+
message: "event_message",
|
10
|
+
event: {
|
11
|
+
event_type: {
|
12
|
+
a: 1
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
context = {custom: {a: "b"}}
|
11
17
|
log_entry = described_class.new("INFO", time, nil, "log message", context, event)
|
12
18
|
msgpack = log_entry.to_msgpack
|
13
|
-
expect(msgpack).to start_with("\
|
19
|
+
expect(msgpack).to start_with("\x85\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z".force_encoding("ASCII-8BIT"))
|
14
20
|
end
|
15
21
|
end
|
16
|
-
end
|
22
|
+
end
|
data/spec/timber/logger_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Timber::Logger
|
3
|
+
describe Timber::Logger do
|
4
4
|
describe "#initialize" do
|
5
5
|
it "shoud select the augmented formatter" do
|
6
6
|
logger = described_class.new(nil)
|
7
|
-
expect(logger.formatter).to be_kind_of(Timber::Logger::
|
7
|
+
expect(logger.formatter).to be_kind_of(Timber::Logger::JSONFormatter)
|
8
8
|
end
|
9
9
|
|
10
10
|
context "development environment" do
|
@@ -24,10 +24,10 @@ describe Timber::Logger, :rails_23 => true do
|
|
24
24
|
it "should allow multiple io devices" do
|
25
25
|
io1 = StringIO.new
|
26
26
|
io2 = StringIO.new
|
27
|
-
logger = Timber::Logger.new(
|
27
|
+
logger = Timber::Logger.new(io1, io2)
|
28
28
|
logger.info("hello world")
|
29
|
-
expect(io1.string).to
|
30
|
-
expect(io2.string).to
|
29
|
+
expect(io1.string).to include("hello world")
|
30
|
+
expect(io2.string).to include("hello world")
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should allow multiple io devices and loggers" do
|
@@ -35,10 +35,10 @@ describe Timber::Logger, :rails_23 => true do
|
|
35
35
|
io2 = StringIO.new
|
36
36
|
io3 = StringIO.new
|
37
37
|
extra_logger = ::Logger.new(io3)
|
38
|
-
logger = Timber::Logger.new(
|
38
|
+
logger = Timber::Logger.new(io1, io2, extra_logger)
|
39
39
|
logger.info("hello world")
|
40
|
-
expect(io1.string).to
|
41
|
-
expect(io2.string).to
|
40
|
+
expect(io1.string).to include("hello world")
|
41
|
+
expect(io2.string).to include("hello world")
|
42
42
|
expect(io3.string).to end_with("hello world\n")
|
43
43
|
end
|
44
44
|
end
|
@@ -88,7 +88,7 @@ describe Timber::Logger, :rails_23 => true do
|
|
88
88
|
|
89
89
|
it "should accept non-strings" do
|
90
90
|
logger.info(true)
|
91
|
-
expect(io.string).to
|
91
|
+
expect(io.string).to include("true")
|
92
92
|
end
|
93
93
|
|
94
94
|
context "with a context" do
|
@@ -101,10 +101,11 @@ describe Timber::Logger, :rails_23 => true do
|
|
101
101
|
)
|
102
102
|
end
|
103
103
|
|
104
|
-
|
105
|
-
Timber::CurrentContext.
|
106
|
-
|
107
|
-
|
104
|
+
before(:each) do |example|
|
105
|
+
Timber::CurrentContext.add(http_context)
|
106
|
+
end
|
107
|
+
after(:each) do |example|
|
108
|
+
Timber::CurrentContext.remove(:http)
|
108
109
|
end
|
109
110
|
|
110
111
|
it "should snapshot and include the context" do
|
@@ -115,19 +116,11 @@ describe Timber::Logger, :rails_23 => true do
|
|
115
116
|
end
|
116
117
|
end
|
117
118
|
|
118
|
-
it "should
|
119
|
+
it "should pass hash as metadata" do
|
119
120
|
message = {message: "payment rejected", payment_rejected: {customer_id: "abcde1234", amount: 100}}
|
120
|
-
expect(Timber::Events).to receive(:build).with(message).and_call_original
|
121
121
|
logger.info(message)
|
122
122
|
expect(io.string).to start_with("payment rejected @metadata {\"level\":\"info\",\"dt\":\"2016-09-01T12:00:00.000000Z\",")
|
123
|
-
expect(io.string).to include("\"
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should log properly when a Timber::Event object is passed" do
|
127
|
-
message = Timber::Events::SQLQuery.new(sql: "select * from users", time_ms: 56, message: "select * from users")
|
128
|
-
logger.info(message)
|
129
|
-
expect(io.string).to start_with("select * from users @metadata {\"level\":\"info\",\"dt\":\"2016-09-01T12:00:00.000000Z\",")
|
130
|
-
expect(io.string).to include("\"event\":{\"sql_query\":{\"sql\":\"select * from users\",\"time_ms\":56.0}}")
|
123
|
+
expect(io.string).to include("\"payment_rejected\":{\"customer_id\":\"abcde1234\",\"amount\":100}")
|
131
124
|
end
|
132
125
|
|
133
126
|
it "should allow :tag" do
|
@@ -149,7 +142,7 @@ describe Timber::Logger, :rails_23 => true do
|
|
149
142
|
{message: "payment rejected", payment_rejected: {customer_id: "abcde1234", amount: 100}}
|
150
143
|
end
|
151
144
|
expect(io.string).to start_with("payment rejected @metadata {\"level\":\"info\",\"dt\":\"2016-09-01T12:00:00.000000Z\",")
|
152
|
-
expect(io.string).to include("\"
|
145
|
+
expect(io.string).to include("\"payment_rejected\":{\"customer_id\":\"abcde1234\",\"amount\":100}")
|
153
146
|
end
|
154
147
|
|
155
148
|
it "should escape new lines" do
|
@@ -181,14 +174,14 @@ describe Timber::Logger, :rails_23 => true do
|
|
181
174
|
let(:logger) { Timber::Logger.new(io) }
|
182
175
|
|
183
176
|
it "should allow default usage" do
|
184
|
-
logger.error("message")
|
185
|
-
expect(io.string).to
|
177
|
+
logger.error("log message")
|
178
|
+
expect(io.string).to include("log message")
|
186
179
|
expect(io.string).to include('"level":"error"')
|
187
180
|
end
|
188
181
|
|
189
182
|
it "should allow messages with options" do
|
190
|
-
logger.error("message", tag: "tag")
|
191
|
-
expect(io.string).to
|
183
|
+
logger.error("log message", tag: "tag")
|
184
|
+
expect(io.string).to include("log message")
|
192
185
|
expect(io.string).to include('"level":"error"')
|
193
186
|
expect(io.string).to include('"tags":["tag"]')
|
194
187
|
end
|
@@ -214,55 +207,21 @@ describe Timber::Logger, :rails_23 => true do
|
|
214
207
|
let(:logger) { Timber::Logger.new(io) }
|
215
208
|
|
216
209
|
it "should allow default usage" do
|
217
|
-
logger.info("message")
|
218
|
-
expect(io.string).to
|
210
|
+
logger.info("log message")
|
211
|
+
expect(io.string).to include("log message")
|
219
212
|
expect(io.string).to include('"level":"info"')
|
220
213
|
end
|
221
214
|
|
222
215
|
it "should allow messages with options" do
|
223
|
-
logger.info("message", tag: "tag")
|
224
|
-
expect(io.string).to
|
216
|
+
logger.info("log message", tag: "tag")
|
217
|
+
expect(io.string).to include("log message")
|
225
218
|
expect(io.string).to include('"level":"info"')
|
226
219
|
expect(io.string).to include('"tags":["tag"]')
|
227
220
|
end
|
228
221
|
|
229
222
|
it "should accept non-string messages" do
|
230
223
|
logger.info(true)
|
231
|
-
expect(io.string).to
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe "#silence" do
|
236
|
-
let(:io) { StringIO.new }
|
237
|
-
let(:logger) { Timber::Logger.new(io) }
|
238
|
-
|
239
|
-
it "should silence the logs" do
|
240
|
-
logger.silence do
|
241
|
-
logger.info("test")
|
242
|
-
end
|
243
|
-
|
244
|
-
expect(io.string).to eq("")
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe "#with_context" do
|
249
|
-
let(:io) { StringIO.new }
|
250
|
-
let(:logger) { Timber::Logger.new(io) }
|
251
|
-
|
252
|
-
it "should add context" do
|
253
|
-
expect(Timber::CurrentContext.instance.send(:hash)[:custom]).to be_nil
|
254
|
-
|
255
|
-
logger.with_context(build: {version: "1.0.0"}) do
|
256
|
-
expect(Timber::CurrentContext.instance.send(:hash)[:custom]).to eq({:build=>{:version=>"1.0.0"}})
|
257
|
-
|
258
|
-
logger.with_context({testing: {key: "value"}}) do
|
259
|
-
expect(Timber::CurrentContext.instance.send(:hash)[:custom]).to eq({:build=>{:version=>"1.0.0"}, :testing=>{:key=>"value"}})
|
260
|
-
end
|
261
|
-
|
262
|
-
expect(Timber::CurrentContext.instance.send(:hash)[:custom]).to eq({:build=>{:version=>"1.0.0"}})
|
263
|
-
end
|
264
|
-
|
265
|
-
expect(Timber::CurrentContext.instance.send(:hash)[:custom]).to be_nil
|
224
|
+
expect(io.string).to include("true")
|
266
225
|
end
|
267
226
|
end
|
268
|
-
end
|
227
|
+
end
|