Class: Rack::Insight::Config
- Inherits:
-
Object
- Object
- Rack::Insight::Config
- Defined in:
- lib/rack/insight/config.rb
Defined Under Namespace
Classes: ConfigurationError
Constant Summary collapse
- 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 }
- DEFAULTS =
Set false if you want to handle the javascript yourself.
{ # You can augment or replace the default set of panel load paths. # These are the paths where rack-insight will look for panels. # A rack-insight extension gem could place panels in: # lib/foo/bar/ # Since gems' lib/ is automatically shifted onto Ruby load path, this will make the custom panels discoverable: # 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, :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 :filtered_backtrace => @filtered_backtrace, # Full back-traces, or filtered ones? :panel_configs => @panel_configs, # Allow specific panels to have their own configurations, and make it extensible :silence_magic_insight_warnings => @silence_magic_insight_warnings, # Should Rack::Insight warn when the MagicInsight is used? :database => @database, # a hash. Keys :raise_encoding_errors, and :raise_decoding_errors are self explanatory # :raise_encoding_errors # When set to true, if there is an encoding error (unlikely) # it will cause a 500 error on your site. !!!WARNING!!! # :raise_decoding_errors # The bundled panels should work fine with :raise_decoding_errors set to true or false # but custom panel implementations may prefer one over the other # The bundled panels will capture these errors and perform admirably. # Site won't go down unless a custom panel is not handling the errors well. :handle_javascript => @handle_javascript # If Your setup is AMD, and you are handling your javascript module loading, # including that of jQuery, then you will need to set this to false. }
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
-
.database ⇒ Object
readonly
Returns the value of attribute database.
-
.filtered_backtrace ⇒ Object
readonly
Returns the value of attribute filtered_backtrace.
-
.handle_javascript ⇒ Object
readonly
Returns the value of attribute handle_javascript.
-
.log_file ⇒ Object
readonly
Returns the value of attribute log_file.
-
.log_level ⇒ Object
readonly
Returns the value of attribute log_level.
-
.panel_configs ⇒ Object
readonly
Returns the value of attribute panel_configs.
-
.rails_log_copy ⇒ Object
readonly
Returns the value of attribute rails_log_copy.
-
.silence_magic_insight_warnings ⇒ Object
readonly
Returns the value of attribute silence_magic_insight_warnings.
-
.verbosity ⇒ Object
readonly
Returns the value of attribute verbosity.
Class Method Summary collapse
- .configure {|@config| ... } ⇒ Object
- .logger ⇒ Object
-
.set_panel_config(panel_name_sym, config) ⇒ Object
To preserve :panel_configs settings from extension libraries, and allowing user config to override the defaults set in this, or other extension gems.
- .validate_config(key, klass) ⇒ Object
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def config @config end |
.database ⇒ Object (readonly)
Returns the value of attribute database.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def database @database end |
.filtered_backtrace ⇒ Object (readonly)
Returns the value of attribute filtered_backtrace.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def filtered_backtrace @filtered_backtrace end |
.handle_javascript ⇒ Object (readonly)
Returns the value of attribute handle_javascript.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def handle_javascript @handle_javascript end |
.log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def log_file @log_file end |
.log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def log_level @log_level end |
.panel_configs ⇒ Object (readonly)
Returns the value of attribute panel_configs.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def panel_configs @panel_configs end |
.rails_log_copy ⇒ Object (readonly)
Returns the value of attribute rails_log_copy.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def rails_log_copy @rails_log_copy end |
.silence_magic_insight_warnings ⇒ Object (readonly)
Returns the value of attribute silence_magic_insight_warnings.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def silence_magic_insight_warnings @silence_magic_insight_warnings end |
.verbosity ⇒ Object (readonly)
Returns the value of attribute verbosity.
22 23 24 |
# File 'lib/rack/insight/config.rb', line 22 def verbosity @verbosity end |
Class Method Details
.configure {|@config| ... } ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rack/insight/config.rb', line 92 def self.configure &block yield @config logger.debug("Rack::Insight::Config#configure:\n called from: #{caller[0]}\n with: #{@config}") if config[:verbosity] == true || config[:verbosity].respond_to?(:<) && config[:verbosity] <= 1 @logger = config[:logger] if @logger.nil? @log_level = config[:log_level] @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] @handle_javascript = !!config[:handle_javascript] # Cast to boolean config[:panel_configs].each do |panel_name_sym, config| set_panel_config(panel_name_sym, config) end validate_config(:panel_configs, Hash) validate_config(:panel_load_paths, Array) validate_config(:database, Hash) end |
.logger ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/rack/insight/config.rb', line 142 def self.logger @logger ||= begin logga = self.config[:logger] if logga.nil? warn ("Rack::Insight::Config#configure: logger is not configured, defaults to Ruby's Logger") logga = ::Logger.new(log_file) if logga.respond_to?(:level) logga.level = self.log_level elsif logga.respond_to?(:sev_threshold) logga.sev_threshold = self.log_level end end logga end end |
.set_panel_config(panel_name_sym, config) ⇒ Object
To preserve :panel_configs settings from extension libraries, and allowing user config to override the defaults set in this, or other extension gems.
133 134 135 136 |
# File 'lib/rack/insight/config.rb', line 133 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 |
.validate_config(key, klass) ⇒ Object
120 121 122 |
# File 'lib/rack/insight/config.rb', line 120 def self.validate_config(key, klass) raise ConfigurationError.new(key, klass.to_s) unless config[key].kind_of?(klass) end |