rack-insight 0.5.4 → 0.5.5
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.
- data/Gemfile.lock +1 -1
- data/lib/rack/insight/app.rb +10 -18
- data/lib/rack/insight/config.rb +35 -5
- data/lib/rack/insight/database.rb +2 -2
- data/lib/rack/insight/instrumentation/instrument.rb +9 -7
- data/lib/rack/insight/instrumentation/probe.rb +2 -1
- data/lib/rack/insight/logging.rb +33 -0
- data/lib/rack/insight/panel.rb +8 -6
- data/lib/rack/insight/panels/active_resource_panel.rb +1 -1
- data/lib/rack/insight/panels/cache_panel.rb +3 -2
- data/lib/rack/insight/panels/sql_panel.rb +1 -1
- data/lib/rack/insight/path-filter.rb +3 -3
- data/lib/rack/insight/render.rb +33 -14
- data/lib/rack/insight/toolbar.rb +1 -1
- data/lib/rack/insight/version.rb +1 -1
- data/lib/rack/insight.rb +3 -0
- data/spec/fixtures/star_trek_panel.rb +6 -1
- data/spec/fixtures/views/star_trek.html.erb +17 -0
- data/spec/rack/insight/config_spec.rb +4 -2
- data/spec/rack/insight/panels/active_record_panel_spec.rb +1 -0
- data/spec/rack/insight/panels/cache_panel_spec.rb +1 -0
- data/spec/rack/insight/panels/log_panel_spec.rb +1 -0
- data/spec/rack/insight/panels/rails_info_panel_spec.rb +1 -0
- data/spec/rack/insight/panels/redis_panel_spec.rb +1 -0
- data/spec/rack/insight/panels/sql_panel_spec.rb +1 -0
- data/spec/rack/insight/panels/templates_panel_spec.rb +1 -0
- data/spec/rack/insight/panels/timer_panel_spec.rb +1 -0
- data/spec/spec_helper.rb +8 -1
- metadata +5 -3
- data/lib/rack/insight/logger.rb +0 -53
data/Gemfile.lock
CHANGED
data/lib/rack/insight/app.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'rack'
|
|
2
2
|
require "digest/sha1"
|
|
3
3
|
require "rack/insight/config"
|
|
4
|
-
require "rack/insight/
|
|
4
|
+
require "rack/insight/logging"
|
|
5
5
|
require "rack/insight/filtered_backtrace"
|
|
6
6
|
require "rack/insight/options"
|
|
7
7
|
require "rack/insight/panel"
|
|
@@ -20,12 +20,12 @@ require 'rack/insight/panels-header'
|
|
|
20
20
|
|
|
21
21
|
module Rack::Insight
|
|
22
22
|
class App
|
|
23
|
-
include Options
|
|
23
|
+
include Rack::Insight::Options
|
|
24
|
+
include Rack::Insight::Logging
|
|
25
|
+
|
|
24
26
|
INSIGHT_ROOT = "/__insight__"
|
|
25
27
|
INSIGHT_REGEX = %r{^#{INSIGHT_ROOT}}
|
|
26
28
|
|
|
27
|
-
VERSION = "0.4.4"
|
|
28
|
-
|
|
29
29
|
class SecurityError < StandardError
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -34,16 +34,13 @@ module Rack::Insight
|
|
|
34
34
|
@base_app = app
|
|
35
35
|
@panels = []
|
|
36
36
|
instance_eval(&block) if block_given?
|
|
37
|
-
|
|
38
|
-
@logger = Logger.new(read_option(:log_level), read_option(:log_path))
|
|
39
|
-
Thread.current['rack-insight.logger'] = @logger
|
|
40
37
|
build_normal_stack
|
|
41
38
|
build_debug_stack
|
|
39
|
+
# TODO: Understand when this would be used
|
|
42
40
|
if options[:on_initialize]
|
|
43
41
|
options[:on_initialize].call(self)
|
|
44
42
|
end
|
|
45
43
|
end
|
|
46
|
-
attr_reader :logger
|
|
47
44
|
attr_accessor :panels
|
|
48
45
|
|
|
49
46
|
def call(env)
|
|
@@ -51,10 +48,6 @@ module Rack::Insight
|
|
|
51
48
|
if insight_active?
|
|
52
49
|
@env = env
|
|
53
50
|
self.options = @default_options
|
|
54
|
-
|
|
55
|
-
env['rack-insight.logger'] = @logger
|
|
56
|
-
Thread.current['rack-insight.logger'] = @logger
|
|
57
|
-
|
|
58
51
|
Rack::Insight.enable
|
|
59
52
|
env["rack-insight.panels"] = []
|
|
60
53
|
@debug_stack.call(env)
|
|
@@ -63,7 +56,6 @@ module Rack::Insight
|
|
|
63
56
|
end
|
|
64
57
|
end
|
|
65
58
|
|
|
66
|
-
|
|
67
59
|
def reset(new_options=nil)
|
|
68
60
|
@env = nil
|
|
69
61
|
initialize_options(new_options)
|
|
@@ -168,17 +160,17 @@ module Rack::Insight
|
|
|
168
160
|
def ip_authorized?
|
|
169
161
|
return true unless options["rack-insight.ip_masks"]
|
|
170
162
|
|
|
171
|
-
logger.
|
|
163
|
+
logger.info{ "Checking #{@original_request.ip} against ip_masks" } if verbose(:low)
|
|
172
164
|
ip = IPAddr.new(@original_request.ip)
|
|
173
165
|
|
|
174
166
|
mask = options["rack-insight.ip_masks"].find do |ip_mask|
|
|
175
167
|
ip_mask.include?(ip)
|
|
176
168
|
end
|
|
177
169
|
if mask
|
|
178
|
-
logger.
|
|
170
|
+
logger.info{ "Matched #{mask}" } unless verbose(:silent)
|
|
179
171
|
return true
|
|
180
172
|
else
|
|
181
|
-
logger.
|
|
173
|
+
logger.info{ "Matched no masks" } unless verbose(:silent)
|
|
182
174
|
return false
|
|
183
175
|
end
|
|
184
176
|
end
|
|
@@ -186,12 +178,12 @@ module Rack::Insight
|
|
|
186
178
|
def password_authorized?
|
|
187
179
|
return true unless options["rack-insight.password"]
|
|
188
180
|
|
|
189
|
-
logger.
|
|
181
|
+
logger.info{"Checking password"} if verbose(:low)
|
|
190
182
|
|
|
191
183
|
expected_sha = Digest::SHA1.hexdigest ["rack-insight", options["rack-insight.password"]].join(":")
|
|
192
184
|
actual_sha = @original_request.cookies["rack-insight_password"]
|
|
193
185
|
|
|
194
|
-
logger.
|
|
186
|
+
logger.info{"Password result: #{actual_sha == expected_sha}"} if verbose(:med)
|
|
195
187
|
actual_sha == expected_sha
|
|
196
188
|
end
|
|
197
189
|
end
|
data/lib/rack/insight/config.rb
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
module Rack::Insight
|
|
2
2
|
class Config
|
|
3
3
|
class << self
|
|
4
|
-
|
|
4
|
+
attr_reader :config, :verbosity, :log_file, :log_level, :rails_log_copy
|
|
5
5
|
end
|
|
6
|
+
@log_file = STDOUT
|
|
7
|
+
@log_level = ::Logger::DEBUG
|
|
8
|
+
@logger = nil
|
|
9
|
+
@verbosity = true
|
|
10
|
+
@rails_log_copy = true
|
|
6
11
|
|
|
7
12
|
DEFAULTS = {
|
|
8
13
|
# You can augment or replace the default set of panel load paths.
|
|
@@ -13,18 +18,43 @@ module Rack::Insight
|
|
|
13
18
|
# Rack::Insight::Config.configure do |config|
|
|
14
19
|
# config[:panel_load_paths] << File::join('foo', 'bar')
|
|
15
20
|
# end
|
|
16
|
-
:panel_load_paths => [File::join('rack', 'insight', 'panels')]
|
|
21
|
+
:panel_load_paths => [File::join('rack', 'insight', 'panels')],
|
|
22
|
+
:logger => @logger,
|
|
23
|
+
:log_file => @log_file,
|
|
24
|
+
:log_level => @log_level,
|
|
25
|
+
:rails_log_copy => @rails_log_copy, # Only has effect when logger is the Rack::Insight::Logger, or a logger behaving like it
|
|
26
|
+
# Can set a specific verbosity: Rack::Insight::Logging::VERBOSITY[:debug]
|
|
27
|
+
:verbosity => @verbosity # true is equivalent to relying soley on the log level of each logged message
|
|
17
28
|
}
|
|
18
29
|
|
|
19
|
-
#cattr_reader :config
|
|
20
|
-
#cattr_writer :config
|
|
21
|
-
|
|
22
30
|
@config ||= DEFAULTS
|
|
23
31
|
def self.configure &block
|
|
24
32
|
yield @config
|
|
33
|
+
logger.debug("Config#configure:\n called from: #{caller[0]}\n with: #{@config}")
|
|
34
|
+
@logger = config[:logger]
|
|
35
|
+
@log_level = config[:log_level]
|
|
36
|
+
@log_file = config[:log_file]
|
|
37
|
+
@verbosity = config[:verbosity]
|
|
25
38
|
unless config[:panel_load_paths].kind_of?(Array)
|
|
26
39
|
raise "Rack::Insight::Config.config[:panel_load_paths] is invalid: Expected kind of Array but got #{config[:panel_load_paths].class}"
|
|
27
40
|
end
|
|
28
41
|
end
|
|
42
|
+
|
|
43
|
+
def self.logger
|
|
44
|
+
@logger ||= begin
|
|
45
|
+
logga = self.config[:logger]
|
|
46
|
+
if logga.nil?
|
|
47
|
+
warn ("Rack::Insight::Config#configure: logger is not configured, defaults to Ruby's Logger")
|
|
48
|
+
logga = ::Logger.new(log_file)
|
|
49
|
+
if logga.respond_to?(:level)
|
|
50
|
+
logga.level = self.log_level
|
|
51
|
+
elsif logga.respond_to?(:sev_threshold)
|
|
52
|
+
logga.sev_threshold = self.log_level
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
logga
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
29
59
|
end
|
|
30
60
|
end
|
|
@@ -90,7 +90,7 @@ module Rack::Insight
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def execute(*args)
|
|
93
|
-
logger.info{ ins_args = args.inspect; "(#{[ins_args.length,120].min}/#{ins_args.length})" + ins_args[0..120] }
|
|
93
|
+
#logger.info{ ins_args = args.inspect; "(#{[ins_args.length,120].min}/#{ins_args.length})" + ins_args[0..120] } if verbose(:debug)
|
|
94
94
|
db.execute(*args)
|
|
95
95
|
end
|
|
96
96
|
|
|
@@ -98,7 +98,7 @@ module Rack::Insight
|
|
|
98
98
|
@table_name = table_name
|
|
99
99
|
@keys = keys
|
|
100
100
|
if(execute("select * from sqlite_master where name = ?", table_name).empty?)
|
|
101
|
-
logger.
|
|
101
|
+
logger.info{ "Initializing a table called #{table_name}" } if verbose(:med)
|
|
102
102
|
execute(create_sql)
|
|
103
103
|
end
|
|
104
104
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'rack/insight/instrumentation/backstage'
|
|
2
|
-
require 'rack/insight/
|
|
2
|
+
require 'rack/insight/logging'
|
|
3
3
|
|
|
4
4
|
module Rack::Insight
|
|
5
5
|
module Instrumentation
|
|
@@ -34,9 +34,9 @@ module Rack::Insight
|
|
|
34
34
|
@collectors = nil
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
include Backstage
|
|
37
|
+
include Rack::Insight::Instrumentation::Backstage
|
|
38
38
|
|
|
39
|
-
include Logging
|
|
39
|
+
include Rack::Insight::Logging
|
|
40
40
|
|
|
41
41
|
def run(object, context="::", kind=:instance, called_at = caller[0], method = "<unknown>", args=[], &blk)
|
|
42
42
|
file, line, rest = called_at.split(':')
|
|
@@ -62,14 +62,16 @@ module Rack::Insight
|
|
|
62
62
|
collectors = probe_chain.inject([]) do |list, probe|
|
|
63
63
|
probe.collectors(method_call.method)
|
|
64
64
|
end
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
if verbose(:debug)
|
|
66
|
+
logger.debug do
|
|
67
|
+
"Probe chain for: #{method_call.context} #{method_call.kind} #{method_call.method}:\n #{collectors.map{|col| col.class.name}.join(", ")}"
|
|
68
|
+
end
|
|
67
69
|
end
|
|
68
70
|
collectors
|
|
69
71
|
end
|
|
70
72
|
|
|
71
73
|
def start_event(method_call, arguments)
|
|
72
|
-
logger.debug{ "Starting event: #{method_call.context} #{method_call.kind} #{method_call.method}" }
|
|
74
|
+
logger.debug{ "Starting event: #{method_call.context} #{method_call.kind} #{method_call.method}" } if verbose(:high)
|
|
73
75
|
|
|
74
76
|
collectors_for(method_call).each do |collector|
|
|
75
77
|
collector.before_detect(method_call, arguments)
|
|
@@ -78,7 +80,7 @@ module Rack::Insight
|
|
|
78
80
|
|
|
79
81
|
def finish_event(method_call, arguments, start_time, result)
|
|
80
82
|
timing = Timing.new(@start, start_time, Time.now)
|
|
81
|
-
logger.debug{ "Finishing event: #{method_call.context} #{method_call.kind} #{method_call.method}" }
|
|
83
|
+
logger.debug{ "Finishing event: #{method_call.context} #{method_call.kind} #{method_call.method}" } if verbose(:high)
|
|
82
84
|
collectors_for(method_call).each do |collector|
|
|
83
85
|
collector.after_detect(method_call, timing, arguments, result)
|
|
84
86
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Rack::Insight
|
|
2
|
+
module Logging
|
|
3
|
+
VERBOSITY = {
|
|
4
|
+
:debug => Logger::DEBUG,
|
|
5
|
+
:high => Logger::INFO,
|
|
6
|
+
:med => Logger::WARN,
|
|
7
|
+
:low => Logger::ERROR,
|
|
8
|
+
# Silent can be used with unless instead of if. Example:
|
|
9
|
+
# logger.info("some message") unless app.verbose(:silent)
|
|
10
|
+
:silent => Logger::FATAL
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
def logger
|
|
14
|
+
Rack::Insight::Config.logger
|
|
15
|
+
end
|
|
16
|
+
module_function :logger
|
|
17
|
+
|
|
18
|
+
# max_level is confusing because the 'level' of output goes up (and this is what max refers to)
|
|
19
|
+
# when the integer value goes DOWN
|
|
20
|
+
def verbose(max_level = false)
|
|
21
|
+
#logger.unknown "Rack::Insight::Config.verbosity: #{Rack::Insight::Config.verbosity} <= max_level: #{VERBOSITY[max_level]}" #for debugging the logger
|
|
22
|
+
return false if (!Rack::Insight::Config.verbosity) # false results in Exactly Zero output!
|
|
23
|
+
return true if (Rack::Insight::Config.verbosity == true) # Not checking truthy because need to check against max_level...
|
|
24
|
+
# Example: if configured log spam level is high (1) logger should get all messages that are not :debug (0)
|
|
25
|
+
# so, if a log statement has if verbose(:low) (:low is 3)
|
|
26
|
+
# 1 <= 3 # true => Message sent to logger
|
|
27
|
+
# then, if a log statement has if verbose(:debug) (:debug is 0)
|
|
28
|
+
# 1 <= 0 # false => Nothing sent to logger
|
|
29
|
+
return true if Rack::Insight::Config.verbosity <= (VERBOSITY[max_level]) # Integers!
|
|
30
|
+
end
|
|
31
|
+
module_function :verbose
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/rack/insight/panel.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require "erb"
|
|
2
|
-
require "rack/insight/
|
|
2
|
+
require "rack/insight/logging"
|
|
3
3
|
require 'rack/insight/database'
|
|
4
4
|
require 'rack/insight/instrumentation'
|
|
5
5
|
require 'rack/insight/render'
|
|
@@ -17,6 +17,7 @@ module Rack::Insight
|
|
|
17
17
|
attr_reader :request
|
|
18
18
|
|
|
19
19
|
class << self
|
|
20
|
+
attr_accessor :template_root
|
|
20
21
|
def file_index
|
|
21
22
|
return @file_index ||= Hash.new do |h,k|
|
|
22
23
|
h[k] = []
|
|
@@ -40,7 +41,7 @@ module Rack::Insight
|
|
|
40
41
|
Thread::current['rack-panel_file'] = old_rel
|
|
41
42
|
end
|
|
42
43
|
|
|
43
|
-
def current_panel_file
|
|
44
|
+
def current_panel_file(sub)
|
|
44
45
|
return Thread::current['rack-panel_file'] ||
|
|
45
46
|
begin
|
|
46
47
|
file_name = nil
|
|
@@ -58,13 +59,14 @@ module Rack::Insight
|
|
|
58
59
|
end
|
|
59
60
|
break unless file_name.nil?
|
|
60
61
|
end
|
|
62
|
+
sub.template_root = File.dirname(matched_line.split(':')[0]) if matched_line.respond_to?(:split)
|
|
61
63
|
file_name
|
|
62
64
|
end
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
def inherited(sub)
|
|
66
|
-
if filename = current_panel_file
|
|
67
|
-
Panel::file_index[
|
|
68
|
+
if filename = current_panel_file(sub)
|
|
69
|
+
Panel::file_index[filename] << sub
|
|
68
70
|
else
|
|
69
71
|
warn "Rack::Insight::Panel inherited by #{sub.name} outside rack-insight's :panel_load_paths. Discarded. Configured panel load paths are: #{Rack::Insight::Config.config[:panel_load_paths].inspect}"
|
|
70
72
|
end
|
|
@@ -87,11 +89,11 @@ module Rack::Insight
|
|
|
87
89
|
|
|
88
90
|
def call(env)
|
|
89
91
|
@env = env
|
|
90
|
-
logger.debug{ "Before call: #{self.name}" }
|
|
92
|
+
logger.debug{ "Before call: #{self.name}" } if verbose(:debug)
|
|
91
93
|
before(env)
|
|
92
94
|
status, headers, body = @app.call(env)
|
|
93
95
|
@request = Rack::Request.new(env)
|
|
94
|
-
logger.debug{ "After call: #{self.name}" }
|
|
96
|
+
logger.debug{ "After call: #{self.name}" } if verbose(:debug)
|
|
95
97
|
after(env, status, headers, body)
|
|
96
98
|
env["rack-insight.panels"] << self
|
|
97
99
|
return [status, headers, body]
|
|
@@ -41,7 +41,7 @@ module Rack::Insight
|
|
|
41
41
|
|
|
42
42
|
def content_for_request(number)
|
|
43
43
|
queries = retrieve(number)
|
|
44
|
-
logger.debug{ "ARes: #{queries.inspect}" }
|
|
44
|
+
logger.debug{ "ARes: #{queries.inspect}" } if verbose(:debug)
|
|
45
45
|
render_template "panels/active_resource", :queries => queries
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -39,7 +39,7 @@ module Rack::Insight
|
|
|
39
39
|
if(defined? Dalli and Dalli::Client === method_call.object)
|
|
40
40
|
method, key = args[0], args[1]
|
|
41
41
|
end
|
|
42
|
-
logger.info{ "Cache panel got #{method} #{key.inspect}" }
|
|
42
|
+
logger.info{ "Cache panel got #{method} #{key.inspect}" } if verbose(:high)
|
|
43
43
|
@stats.record_call(method, timing.duration, !result.nil?, key)
|
|
44
44
|
end
|
|
45
45
|
|
|
@@ -58,7 +58,8 @@ module Rack::Insight
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def content_for_request(number)
|
|
61
|
-
|
|
61
|
+
# TODO: What is this syntax with the double {{}}?
|
|
62
|
+
logger.debug{{ :req_num => number }} if verbose(:debug)
|
|
62
63
|
stats = retrieve(number).first
|
|
63
64
|
render_template "panels/cache", :stats => stats
|
|
64
65
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
require 'rack/insight/
|
|
1
|
+
require 'rack/insight/logging'
|
|
2
2
|
|
|
3
3
|
module Rack::Insight
|
|
4
4
|
class PathFilter
|
|
5
|
-
include Logging
|
|
5
|
+
include Rack::Insight::Logging
|
|
6
6
|
def initialize(app)
|
|
7
7
|
@app = app
|
|
8
8
|
end
|
|
@@ -16,7 +16,7 @@ module Rack::Insight
|
|
|
16
16
|
return [404, {}, []]
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
logger.debug{ "Shortcutting collection stack: #{filter} =~ #{env['PATH_INFO']}"}
|
|
19
|
+
logger.debug{ "Shortcutting collection stack: #{filter} =~ #{env['PATH_INFO']}"} if verbose(:debug)
|
|
20
20
|
return @app.call(env)
|
|
21
21
|
end
|
|
22
22
|
end
|
data/lib/rack/insight/render.rb
CHANGED
|
@@ -49,26 +49,45 @@ module Rack::Insight
|
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
#def compiled_source(filename)
|
|
53
|
+
# primary_file_path = ::File.join(::File.dirname(__FILE__), "views/#{filename}.html.erb")
|
|
54
|
+
# file = nil
|
|
55
|
+
# begin
|
|
56
|
+
# file = ::File.read(primary_file_path)
|
|
57
|
+
# rescue Errno::ENOENT
|
|
58
|
+
# end
|
|
59
|
+
# if file.nil?
|
|
60
|
+
# Rack::Insight::Config.config[:panel_load_paths].each do |load_path|
|
|
61
|
+
# begin
|
|
62
|
+
# file = ::File.read(::File.join(load_path, "#{filename}.html.erb"))
|
|
63
|
+
# break # If no error is raised then the file was read!
|
|
64
|
+
# rescue Errno::ENOENT
|
|
65
|
+
# end
|
|
66
|
+
# end
|
|
67
|
+
# end
|
|
68
|
+
# if file
|
|
69
|
+
# ::ERB.new(file, nil, "-").src
|
|
70
|
+
# else
|
|
71
|
+
# logger.fatal("Rack::Insight: Unable to find expected view template #{primary_file_path} or a #{filename}.html.erb template in rack-insight's :panel_load_paths. Configured panel load paths are: #{Rack::Insight::Config.config[:panel_load_paths].inspect}")
|
|
72
|
+
# end
|
|
73
|
+
#end
|
|
74
|
+
|
|
52
75
|
def compiled_source(filename)
|
|
53
|
-
|
|
76
|
+
templates = []
|
|
77
|
+
templates << ::File.join(::File.dirname(__FILE__), "views/#{filename}.html.erb")
|
|
78
|
+
templates << ::File.join(::File.join(self.class.template_root, "#{filename}.html.erb")) if self.class.respond_to?(:template_root)
|
|
54
79
|
file = nil
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Rack::Insight::Config.config[:panel_load_paths].each do |load_path|
|
|
61
|
-
begin
|
|
62
|
-
file = ::File.read(::File.join(load_path, "#{filename}.html.erb"))
|
|
63
|
-
break # If no error is raised then the file was read!
|
|
64
|
-
rescue Errno::ENOENT
|
|
65
|
-
end
|
|
80
|
+
templates.each do |template_path|
|
|
81
|
+
begin
|
|
82
|
+
file = ::File.read(template_path)
|
|
83
|
+
break # If no error is raised then the file was read!
|
|
84
|
+
rescue Errno::ENOENT
|
|
66
85
|
end
|
|
67
86
|
end
|
|
68
87
|
if file
|
|
69
|
-
|
|
88
|
+
::ERB.new(file, nil, "-").src
|
|
70
89
|
else
|
|
71
|
-
|
|
90
|
+
logger.fatal("Rack::Insight: Unable to find expected view template #{filename} in any of the following locations: #{templates.inspect}")
|
|
72
91
|
end
|
|
73
92
|
end
|
|
74
93
|
|
data/lib/rack/insight/toolbar.rb
CHANGED
|
@@ -50,7 +50,7 @@ module Rack::Insight
|
|
|
50
50
|
{ :id => row[0], :method => row[1], :path => row[2] }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
logger.info{ "Injecting toolbar: active panels: #{@insight.panels.map{|pnl| pnl.class.name}.inspect}" }
|
|
53
|
+
logger.info{ "Injecting toolbar: active panels: #{@insight.panels.map{|pnl| pnl.class.name}.inspect}" } unless verbose(:silent)
|
|
54
54
|
|
|
55
55
|
headers_fragment = render_template("headers_fragment",
|
|
56
56
|
:panels => @insight.panels,
|
data/lib/rack/insight/version.rb
CHANGED
data/lib/rack/insight.rb
CHANGED
|
@@ -6,14 +6,16 @@ describe Rack::Insight::Config do
|
|
|
6
6
|
before(:each) do
|
|
7
7
|
Rack::Insight::Config.configure do |config|
|
|
8
8
|
# spec folder is in the load path during specs!
|
|
9
|
-
config[:panel_load_paths] <<
|
|
9
|
+
config[:panel_load_paths] << 'fixtures'
|
|
10
10
|
end
|
|
11
11
|
require 'fixtures/star_trek_panel'
|
|
12
12
|
reset_insight :panel_files => %w{star_trek_panel}
|
|
13
13
|
end
|
|
14
14
|
it "should use StarTrekPanel" do
|
|
15
15
|
app.insight_app.panel_classes.include?(StarTrekPanel).should be_true
|
|
16
|
-
get_via_rack "/"
|
|
16
|
+
#get_via_rack "/"
|
|
17
|
+
response = get "/", :content_type => "application/xhtml+xml"
|
|
18
|
+
response.should have_selector("table#StarTrek", :content => 'Enterprise')
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -12,6 +12,14 @@ require "fixtures/sample_app"
|
|
|
12
12
|
require "fixtures/dummy_panel"
|
|
13
13
|
require "rack/insight/rspec_matchers"
|
|
14
14
|
|
|
15
|
+
# Will use the default Ruby Logger.
|
|
16
|
+
Rack::Insight::Config.configure do |config|
|
|
17
|
+
config[:verbosity] = Rack::Insight::Logging::VERBOSITY[:silent]
|
|
18
|
+
config[:log_level] = ::Logger::INFO
|
|
19
|
+
end
|
|
20
|
+
puts "Log Level for specs is #{::Logger::ERROR}"
|
|
21
|
+
puts "Verbosity level for specs is #{Rack::Insight::Logging::VERBOSITY.select {|k,v| v == Rack::Insight::Config.verbosity }.keys.first.inspect} or #{Rack::Insight::Config.verbosity}"
|
|
22
|
+
|
|
15
23
|
RSpec.configure do |config|
|
|
16
24
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
17
25
|
config.run_all_when_everything_filtered = true
|
|
@@ -31,7 +39,6 @@ RSpec.configure do |config|
|
|
|
31
39
|
config.include Rack::Insight::RspecMatchers
|
|
32
40
|
|
|
33
41
|
config.before do
|
|
34
|
-
Thread.current["rack-insight.logger"] = Rack::Insight::Logger.new(Logger::FATAL, "")
|
|
35
42
|
@added_constants = []
|
|
36
43
|
end
|
|
37
44
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rack-insight
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -12,7 +12,7 @@ authors:
|
|
|
12
12
|
autorequire:
|
|
13
13
|
bindir: bin
|
|
14
14
|
cert_chain: []
|
|
15
|
-
date: 2012-08-
|
|
15
|
+
date: 2012-08-31 00:00:00.000000000 Z
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
18
18
|
name: rack
|
|
@@ -230,7 +230,7 @@ files:
|
|
|
230
230
|
- lib/rack/insight/instrumentation/probe-definition.rb
|
|
231
231
|
- lib/rack/insight/instrumentation/probe.rb
|
|
232
232
|
- lib/rack/insight/instrumentation/setup.rb
|
|
233
|
-
- lib/rack/insight/
|
|
233
|
+
- lib/rack/insight/logging.rb
|
|
234
234
|
- lib/rack/insight/options.rb
|
|
235
235
|
- lib/rack/insight/panel.rb
|
|
236
236
|
- lib/rack/insight/panel_app.rb
|
|
@@ -311,6 +311,7 @@ files:
|
|
|
311
311
|
- spec/fixtures/dummy_panel.rb
|
|
312
312
|
- spec/fixtures/sample_app.rb
|
|
313
313
|
- spec/fixtures/star_trek_panel.rb
|
|
314
|
+
- spec/fixtures/views/star_trek.html.erb
|
|
314
315
|
- spec/insight_spec.rb
|
|
315
316
|
- spec/instrumentation_spec.rb
|
|
316
317
|
- spec/rack/insight/config_spec.rb
|
|
@@ -359,6 +360,7 @@ test_files:
|
|
|
359
360
|
- spec/fixtures/dummy_panel.rb
|
|
360
361
|
- spec/fixtures/sample_app.rb
|
|
361
362
|
- spec/fixtures/star_trek_panel.rb
|
|
363
|
+
- spec/fixtures/views/star_trek.html.erb
|
|
362
364
|
- spec/insight_spec.rb
|
|
363
365
|
- spec/instrumentation_spec.rb
|
|
364
366
|
- spec/rack/insight/config_spec.rb
|
data/lib/rack/insight/logger.rb
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
module Rack::Insight
|
|
2
|
-
class Logger
|
|
3
|
-
def initialize(level, path)
|
|
4
|
-
@level = level
|
|
5
|
-
@log_path = path
|
|
6
|
-
@logfile = nil
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
attr_accessor :level
|
|
10
|
-
|
|
11
|
-
DEBUG = 0
|
|
12
|
-
INFO = 1
|
|
13
|
-
WARN = 2
|
|
14
|
-
ERROR = 3
|
|
15
|
-
FATAL = 4
|
|
16
|
-
UNKNOWN = 5
|
|
17
|
-
|
|
18
|
-
def log(severity, message)
|
|
19
|
-
message = message.inspect unless String === message
|
|
20
|
-
return unless severity >= @level
|
|
21
|
-
|
|
22
|
-
if defined? Rails and Rails.respond_to?(:logger) and not Rails.logger.nil?
|
|
23
|
-
Rails.logger.add(severity, "[Rack::Insight]: " + message)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
logfile.puts(message)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def logfile
|
|
30
|
-
@logfile ||= File::open(@log_path, "a+")
|
|
31
|
-
rescue
|
|
32
|
-
$stderr
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def debug; log(DEBUG, yield) end
|
|
36
|
-
def info; log(INFO, yield) end
|
|
37
|
-
def warn; log(WARN, yield) end
|
|
38
|
-
def error; log(ERROR, yield) end
|
|
39
|
-
def fatal; log(FATAL, yield) end
|
|
40
|
-
def unknown; log(UNKNOWN, yield) end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
module Logging
|
|
44
|
-
def logger(env = nil)
|
|
45
|
-
if env.nil?
|
|
46
|
-
Thread.current['rack-insight.logger'] ||= Rack::Insight::Logger.new(Logger::DEBUG, "")
|
|
47
|
-
else
|
|
48
|
-
env["rack-insight.logger"] ||= Rack::Insight::Logger.new(Logger::DEBUG, "")
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
module_function :logger
|
|
52
|
-
end
|
|
53
|
-
end
|