Permalink
Browse files

Merge pull request #18 from alphagov/debug_mode

Disable Slimmer debug logging by default.
  • Loading branch information...
2 parents aefc467 + ccf3145 commit b421238580741663d3ec25877e16c71479f9d5f4 @jystewart jystewart committed Sep 21, 2012
Showing with 29 additions and 2 deletions.
  1. +19 −0 README.md
  2. +10 −2 lib/slimmer/app.rb
View
@@ -53,6 +53,25 @@ To get this, include Slimmer::Template in your controller:
include Slimmer::Template
end
+## Logging
+
+Slimmer can be configured with a logger by passing in a logger instance (anything that quacks like an instance of Logger).
+For example to log to the Rails log, put the following in an initializer:
+
+ YourApp::Application.configure do
+ config.slimmer.logger = Rails.logger
+ end
+
+**Note:** This can't be in `application.rb` because the Rails logger hasn't been initialized by then.
+
+**Debug logging**
+
+By default if you pass in a logger with its log level set to debug, slimmer will dup this logger and reduce the level to info. (Slimmer's debug logging is very noisy). To prevent this, set the `enable_debugging` option to true. e.g. for Rails:
+
+ YourApp::Application.configure do
+ config.slimmer.enable_debugging = true
+ end
+
## The name
Slimmer was extracted from a much larger project called 'skinner'. 'slimmer' referred to the size
View
@@ -1,14 +1,22 @@
module Slimmer
class App
attr_accessor :logger
- private :logger=, :logger
def initialize(app, *args, &block)
options = args.first || {}
@app = app
logger = options[:logger] || NullLogger.instance
self.logger = logger
+ begin
+ if logger.level == 0 # Log set to debug level
+ unless options[:enable_debugging]
+ self.logger = logger.dup
+ self.logger.level = 1 # info
+ end
+ end
+ rescue NoMethodError # In case logger doesn't respond_to? :level
+ end
if options.key? :template_path
raise "Template path should not be used. Use asset_host instead."
@@ -18,7 +26,7 @@ def initialize(app, *args, &block)
options[:asset_host] = Plek.current.find("assets")
end
- @skin = Skin.new options.merge(logger: logger)
+ @skin = Skin.new options.merge(logger: self.logger)
end
def call(env)

0 comments on commit b421238

Please sign in to comment.