Created
February 22, 2013 16:14
-
-
Save stevenharman/5014534 to your computer and use it in GitHub Desktop.
Peaceful Asset Logger. You know, for Rails. Silence all of the `assets` noise in your development logs. Inspired by middleware I once saw from @macournoyer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: in develoopment.rb | |
# | |
# config.middleware.insert_before Rails::Rack::Logger, PeacefulAssetsLogger | |
# | |
class PeacefulAssetsLogger | |
def initialize(app) | |
unless ENV[ 'LOG_ASSETS' ] | |
puts 'For more peaceful logs we have silenced the asset logs.' | |
puts 'To see asset requests in the logs, set LOG_ASSETS=true env variable.' | |
Rails.application.assets.logger = Logger.new('/dev/null') | |
end | |
@app = app | |
end | |
def call(env) | |
previous_level = Rails.logger.level | |
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index('/assets/') == 0 && !ENV['LOG_ASSETS'] | |
@app.call(env) | |
ensure | |
Rails.logger.level = previous_level | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment