timber 1.1.14 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -2
- data/.travis.yml +47 -0
- data/Gemfile +1 -28
- data/README.md +83 -298
- data/bin/timber +13 -0
- data/gemfiles/rails-3.0.gemfile +5 -0
- data/gemfiles/rails-3.1.gemfile +5 -0
- data/gemfiles/rails-3.2.gemfile +5 -0
- data/gemfiles/rails-4.0.gemfile +9 -0
- data/gemfiles/rails-4.1.gemfile +9 -0
- data/gemfiles/rails-4.2.gemfile +9 -0
- data/gemfiles/rails-5.0.gemfile +9 -0
- data/gemfiles/rails-edge.gemfile +7 -0
- data/lib/timber.rb +7 -7
- data/lib/timber/cli.rb +72 -0
- data/lib/timber/cli/api.rb +104 -0
- data/lib/timber/cli/application.rb +28 -0
- data/lib/timber/cli/install.rb +186 -0
- data/lib/timber/cli/io_helper.rb +58 -0
- data/lib/timber/cli/messages.rb +170 -0
- data/lib/timber/config.rb +47 -6
- data/lib/timber/contexts/http.rb +2 -2
- data/lib/timber/current_context.rb +1 -1
- data/lib/timber/event.rb +8 -0
- data/lib/timber/events.rb +2 -0
- data/lib/timber/events/controller_call.rb +12 -3
- data/lib/timber/events/exception.rb +4 -3
- data/lib/timber/events/http_client_request.rb +61 -0
- data/lib/timber/events/http_client_response.rb +47 -0
- data/lib/timber/events/http_server_request.rb +15 -23
- data/lib/timber/events/http_server_response.rb +9 -9
- data/lib/timber/events/sql_query.rb +2 -2
- data/lib/timber/events/template_render.rb +2 -2
- data/lib/timber/frameworks/rails.rb +31 -6
- data/lib/timber/integrations.rb +22 -0
- data/lib/timber/integrations/action_controller/log_subscriber.rb +25 -0
- data/lib/timber/integrations/action_controller/log_subscriber/timber_log_subscriber.rb +40 -0
- data/lib/timber/integrations/action_dispatch/debug_exceptions.rb +51 -0
- data/lib/timber/integrations/action_view/log_subscriber.rb +25 -0
- data/lib/timber/integrations/action_view/log_subscriber/timber_log_subscriber.rb +73 -0
- data/lib/timber/integrations/active_record/log_subscriber.rb +25 -0
- data/lib/timber/integrations/active_record/log_subscriber/timber_log_subscriber.rb +39 -0
- data/lib/timber/integrations/active_support/tagged_logging.rb +71 -0
- data/lib/timber/integrations/rack.rb +16 -0
- data/lib/timber/integrations/rack/exception_event.rb +28 -0
- data/lib/timber/integrations/rack/http_context.rb +25 -0
- data/lib/timber/integrations/rack/http_events.rb +46 -0
- data/lib/timber/integrations/rack/user_context.rb +59 -0
- data/lib/timber/integrations/rails/rack_logger.rb +49 -0
- data/lib/timber/integrator.rb +24 -0
- data/lib/timber/log_devices/http.rb +14 -21
- data/lib/timber/log_entry.rb +1 -1
- data/lib/timber/logger.rb +38 -12
- data/lib/timber/overrides.rb +9 -0
- data/lib/timber/overrides/lograge.rb +14 -0
- data/lib/timber/overrides/rails_server.rb +10 -0
- data/lib/timber/util.rb +2 -0
- data/lib/timber/util/active_support_log_subscriber.rb +13 -9
- data/lib/timber/util/http_event.rb +54 -0
- data/lib/timber/util/request.rb +44 -0
- data/lib/timber/version.rb +1 -1
- data/spec/README.md +5 -9
- data/spec/spec_helper.rb +1 -4
- data/spec/support/action_controller.rb +7 -3
- data/spec/support/active_record.rb +23 -19
- data/spec/support/rails.rb +56 -32
- data/spec/support/timber.rb +2 -3
- data/spec/support/webmock.rb +1 -0
- data/spec/timber/integrations/action_controller/log_subscriber_spec.rb +55 -0
- data/spec/timber/integrations/action_dispatch/debug_exceptions_spec.rb +53 -0
- data/spec/timber/integrations/action_view/log_subscriber_spec.rb +115 -0
- data/spec/timber/integrations/active_record/log_subscriber_spec.rb +46 -0
- data/spec/timber/integrations/rack/http_context_spec.rb +60 -0
- data/spec/timber/integrations/rails/rack_logger_spec.rb +58 -0
- data/spec/timber/logger_spec.rb +45 -9
- data/timber.gemspec +29 -3
- metadata +143 -46
- data/Appraisals +0 -41
- data/circle.yml +0 -33
- data/lib/timber/overrides/logger_add.rb +0 -38
- data/lib/timber/probe.rb +0 -23
- data/lib/timber/probes.rb +0 -23
- data/lib/timber/probes/action_controller_log_subscriber.rb +0 -20
- data/lib/timber/probes/action_controller_log_subscriber/log_subscriber.rb +0 -64
- data/lib/timber/probes/action_controller_user_context.rb +0 -52
- data/lib/timber/probes/action_dispatch_debug_exceptions.rb +0 -80
- data/lib/timber/probes/action_view_log_subscriber.rb +0 -20
- data/lib/timber/probes/action_view_log_subscriber/log_subscriber.rb +0 -69
- data/lib/timber/probes/active_record_log_subscriber.rb +0 -20
- data/lib/timber/probes/active_record_log_subscriber/log_subscriber.rb +0 -31
- data/lib/timber/probes/active_support_tagged_logging.rb +0 -63
- data/lib/timber/probes/rails_rack_logger.rb +0 -77
- data/lib/timber/rack_middlewares.rb +0 -12
- data/lib/timber/rack_middlewares/http_context.rb +0 -30
- data/spec/support/action_view.rb +0 -4
- data/spec/support/coveralls.rb +0 -2
- data/spec/support/simplecov.rb +0 -9
- data/spec/timber/overrides/logger_add_spec.rb +0 -26
- data/spec/timber/probes/action_controller_log_subscriber_spec.rb +0 -65
- data/spec/timber/probes/action_controller_user_context_spec.rb +0 -53
- data/spec/timber/probes/action_dispatch_debug_exceptions_spec.rb +0 -48
- data/spec/timber/probes/action_view_log_subscriber_spec.rb +0 -107
- data/spec/timber/probes/active_record_log_subscriber_spec.rb +0 -47
- data/spec/timber/probes/rails_rack_logger_spec.rb +0 -46
- data/spec/timber/rack_middlewares/http_context_spec.rb +0 -47
@@ -1,47 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Probes::ActiveRecordLogSubscriber do
|
4
|
-
let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
|
5
|
-
let(:io) { StringIO.new }
|
6
|
-
let(:logger) do
|
7
|
-
logger = Timber::Logger.new(io)
|
8
|
-
logger.level = ::Logger::INFO
|
9
|
-
logger
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "#insert!" do
|
13
|
-
around(:each) do |example|
|
14
|
-
old_logger = ::ActiveRecord::Base.logger
|
15
|
-
::ActiveRecord::Base.logger = logger
|
16
|
-
|
17
|
-
Timecop.freeze(time) { example.run }
|
18
|
-
|
19
|
-
::ActiveRecord::Base.logger = old_logger
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should not log if the level is not sufficient" do
|
23
|
-
User.order("users.id DESC").all.collect # collect kicks the sql because it is lazily executed
|
24
|
-
expect(io.string).to eq("")
|
25
|
-
end
|
26
|
-
|
27
|
-
context "with an info level" do
|
28
|
-
around(:each) do |example|
|
29
|
-
old_level = logger.level
|
30
|
-
logger.level = ::Logger::DEBUG
|
31
|
-
example.run
|
32
|
-
logger.level = old_level
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should log the sql query" do
|
36
|
-
User.order("users.id DESC").all.collect # collect kicks the sql because it is lazily executed
|
37
|
-
# Rails 4.X adds random spaces :/
|
38
|
-
string = io.string.gsub(" ORDER BY", " ORDER BY")
|
39
|
-
string = string.gsub(" ORDER BY", " ORDER BY")
|
40
|
-
expect(string).to include("users.id DESC")
|
41
|
-
expect(string).to include("@metadata")
|
42
|
-
expect(string).to include("\"level\":\"debug\"")
|
43
|
-
expect(string).to include("\"event\":{\"server_side_app\":{\"sql_query\"")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::Probes::RailsRackLogger do
|
4
|
-
describe described_class::InstanceMethods do
|
5
|
-
let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
|
6
|
-
let(:io) { StringIO.new }
|
7
|
-
let(:logger) do
|
8
|
-
logger = Timber::Logger.new(io)
|
9
|
-
logger.level = ::Logger::INFO
|
10
|
-
logger
|
11
|
-
end
|
12
|
-
|
13
|
-
around(:each) do |example|
|
14
|
-
class RailsRackLoggerController < ActionController::Base
|
15
|
-
layout nil
|
16
|
-
|
17
|
-
def index
|
18
|
-
render json: {}
|
19
|
-
end
|
20
|
-
|
21
|
-
def method_for_action(action_name)
|
22
|
-
action_name
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
::RailsApp.routes.draw do
|
27
|
-
get '/rails_rack_logger' => 'rails_rack_logger#index'
|
28
|
-
end
|
29
|
-
|
30
|
-
Timecop.freeze(time) { example.run }
|
31
|
-
|
32
|
-
Object.send(:remove_const, :RailsRackLoggerController)
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#started_request_message" do
|
36
|
-
it "should add the request event" do
|
37
|
-
allow(::Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new("production")) # Rails 3.2.X
|
38
|
-
allow(::Rails).to receive(:logger).and_return(logger) # Rails 3.2.X
|
39
|
-
allow_any_instance_of(::Rails::Rack::Logger).to receive(:logger).and_return(logger)
|
40
|
-
dispatch_rails_request("/rails_rack_logger")
|
41
|
-
expect(io.string).to start_with("Started GET \"/rails_rack_logger\" for 123.456.789.10 @metadata {\"level\":\"info\",\"dt\":\"2016-09-01T12:00:00.000000Z\"")
|
42
|
-
expect(io.string).to include("\"event\":{\"server_side_app\":{\"http_server_request\":{\"host\":\"example.org\",\"method\":\"GET\",\"path\":\"/rails_rack_logger\",\"port\":80,\"headers\":{\"remote_addr\":\"123.456.789.10\",\"request_id\":\"unique-request-id-1234\",\"scheme\":\"http\"}}}")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Timber::RackMiddlewares::HTTPContext do
|
4
|
-
let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
|
5
|
-
let(:io) { StringIO.new }
|
6
|
-
let(:logger) do
|
7
|
-
logger = Timber::Logger.new(io)
|
8
|
-
logger.level = ::Logger::INFO
|
9
|
-
logger
|
10
|
-
end
|
11
|
-
|
12
|
-
around(:each) do |example|
|
13
|
-
class RackHttpController < ActionController::Base
|
14
|
-
layout nil
|
15
|
-
|
16
|
-
def index
|
17
|
-
Thread.current[:_timber_context] = Timber::CurrentContext.instance.snapshot
|
18
|
-
render json: {}
|
19
|
-
end
|
20
|
-
|
21
|
-
def method_for_action(action_name)
|
22
|
-
action_name
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
::RailsApp.routes.draw do
|
27
|
-
get '/rack_http' => 'rack_http#index'
|
28
|
-
end
|
29
|
-
|
30
|
-
Timecop.freeze(time) { example.run }
|
31
|
-
|
32
|
-
Object.send(:remove_const, :RackHttpController)
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#process" do
|
36
|
-
it "should set the context" do
|
37
|
-
allow(Benchmark).to receive(:ms).and_return(1).and_yield
|
38
|
-
allow_any_instance_of(Timber::Probes::ActionControllerLogSubscriber::LogSubscriber).to receive(:logger).and_return(logger)
|
39
|
-
|
40
|
-
dispatch_rails_request("/rack_http")
|
41
|
-
http_context = Thread.current[:_timber_context][:http]
|
42
|
-
|
43
|
-
expect(http_context).to eq({:method=>"GET", :path=>"/rack_http", :remote_addr=>"123.456.789.10", :request_id=>"unique-request-id-1234"})
|
44
|
-
expect(io.string).to include("\"http\":{\"method\":\"GET\",\"path\":\"/rack_http\",\"remote_addr\":\"123.456.789.10\",\"request_id\":\"unique-request-id-1234\"}")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|