lib/rack/insight/config.rb in rack-insight-0.5.26 vs lib/rack/insight/config.rb in rack-insight-0.5.27

- old
+ new

@@ -1,16 +1,29 @@ +require 'logger' # Require the standard Ruby Logger + module Rack::Insight class Config + + VERBOSITY = { + :debug => Logger::DEBUG, + :high => Logger::INFO, + :med => Logger::WARN, + :low => Logger::ERROR, + # Silent can be used with unless instead of if. Example: + # logger.info("some message") unless app.verbose(:silent) + :silent => Logger::FATAL + } + class << self attr_reader :config, :verbosity, :log_file, :log_level, :rails_log_copy, :filtered_backtrace, :panel_configs, :silence_magic_insight_warnings, :database end @log_file = STDOUT @log_level = ::Logger::DEBUG @logger = nil - @verbosity = Rack::Insight::Logging::VERBOSITY[:silent] + @verbosity = nil @rails_log_copy = true @filtered_backtrace = true @panel_configs = { :active_record => {:probes => {'ActiveRecord::Base' => [:class, :allocate]}}, :active_resource => {:probes => {'ActiveResource::Connection' => [:instance, :request]}}, @@ -22,11 +35,15 @@ :sphinx => {:probes => {'Riddle::Client' => [:instance, :request]}}, :sql => {:probes => Hash[%w{ PostgreSQLAdapter MysqlAdapter SQLiteAdapter Mysql2Adapter OracleEnhancedAdapter }.map do |adapter| ["ActiveRecord::ConnectionAdapters::#{adapter}", [:instance, :execute]] end ] }, - :templates => {:probes => {'ActionView::Template' => [:instance, :render]}} + :templates => {:probes => {'ActionView::Template' => [:instance, :render]}}, + :redis => {:probes => defined?(Redis::Client) ? + { 'Redis::Client' => [:instance, :call] } : # Redis >= 3.0.0 + { 'Redis' => [:instance, :call_command] } # Redis < 3.0.0 + } } @silence_magic_insight_warnings = false @database = { :raise_encoding_errors => false, # Either way will be logged :raise_decoding_errors => true, # Either way will be logged @@ -41,10 +58,11 @@ # Rack::Insight::Config.configure do |config| # config[:panel_load_paths] << File::join('foo', 'bar') # end :panel_load_paths => [File::join('rack', 'insight', 'panels')], :logger => @logger, + :verbosity => @verbosity, :log_file => @log_file, :log_level => @log_level, :rails_log_copy => @rails_log_copy, # Only has effect when logger is the Rack::Insight::Logger, or a logger behaving like it # Can set a specific verbosity: Rack::Insight::Logging::VERBOSITY[:debug] :verbosity => @verbosity, # true is equivalent to relying solely on the log level of each logged message @@ -72,10 +90,13 @@ @log_file = config[:log_file] elsif config[:log_level] || config[:log_file] logger.warn("Rack::Insight::Config#configure: when logger is set, log_level and log_file have no effect, and will only confuse you.") end @verbosity = config[:verbosity] + if @verbosity.nil? + @verbosity = Rack::Insight::Config::VERBOSITY[:silent] + end @filtered_backtrace = config[:filtered_backtrace] @silence_magic_insight_warnings = config[:silence_magic_insight_warnings] @database = config[:database] config[:panel_configs].each do |panel_name_sym, config| @@ -101,9 +122,13 @@ # To preserve :panel_configs settings from extension libraries, # and allowing user config to override the defaults set in this, or other extension gems. def self.set_panel_config(panel_name_sym, config) @panel_configs[panel_name_sym].merge!(config) self.config[:panel_configs][panel_name_sym] = @panel_configs[panel_name_sym] + end + + def self.verbosity + @verbosity ||= self.config[:verbosity] end def self.logger @logger ||= begin logga = self.config[:logger]