lib/rack/insight/app.rb in rack-insight-0.5.4 vs lib/rack/insight/app.rb in rack-insight-0.5.5

- old
+ new

@@ -1,9 +1,9 @@ require 'rack' require "digest/sha1" require "rack/insight/config" -require "rack/insight/logger" +require "rack/insight/logging" require "rack/insight/filtered_backtrace" require "rack/insight/options" require "rack/insight/panel" require "rack/insight/panel_app" require "rack/insight/params_signature" @@ -18,54 +18,46 @@ require 'rack/insight/panels-content' require 'rack/insight/panels-header' module Rack::Insight class App - include Options + include Rack::Insight::Options + include Rack::Insight::Logging + INSIGHT_ROOT = "/__insight__" INSIGHT_REGEX = %r{^#{INSIGHT_ROOT}} - VERSION = "0.4.4" - class SecurityError < StandardError end def initialize(app, options = {}, &block) initialize_options options @base_app = app @panels = [] instance_eval(&block) if block_given? - - @logger = Logger.new(read_option(:log_level), read_option(:log_path)) - Thread.current['rack-insight.logger'] = @logger build_normal_stack build_debug_stack + # TODO: Understand when this would be used if options[:on_initialize] options[:on_initialize].call(self) end end - attr_reader :logger attr_accessor :panels def call(env) @original_request = Rack::Request.new(env) if insight_active? @env = env self.options = @default_options - - env['rack-insight.logger'] = @logger - Thread.current['rack-insight.logger'] = @logger - Rack::Insight.enable env["rack-insight.panels"] = [] @debug_stack.call(env) else @normal_stack.call(env) end end - def reset(new_options=nil) @env = nil initialize_options(new_options) Rack::Insight::Instrumentation::ClassProbe::all_probes.each do |probe| @@ -166,33 +158,33 @@ end def ip_authorized? return true unless options["rack-insight.ip_masks"] - logger.debug{ "Checking #{@original_request.ip} against ip_masks" } + logger.info{ "Checking #{@original_request.ip} against ip_masks" } if verbose(:low) ip = IPAddr.new(@original_request.ip) mask = options["rack-insight.ip_masks"].find do |ip_mask| ip_mask.include?(ip) end if mask - logger.debug{ "Matched #{mask}" } + logger.info{ "Matched #{mask}" } unless verbose(:silent) return true else - logger.debug{ "Matched no masks" } + logger.info{ "Matched no masks" } unless verbose(:silent) return false end end def password_authorized? return true unless options["rack-insight.password"] - logger.debug{"Checking password"} + logger.info{"Checking password"} if verbose(:low) expected_sha = Digest::SHA1.hexdigest ["rack-insight", options["rack-insight.password"]].join(":") actual_sha = @original_request.cookies["rack-insight_password"] - logger.debug{"Password result: #{actual_sha == expected_sha}"} + logger.info{"Password result: #{actual_sha == expected_sha}"} if verbose(:med) actual_sha == expected_sha end end end