-
-
Save justinko/1732528 to your computer and use it in GitHub Desktop.
This file contains 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
class NullLogger < Logger | |
def initialize(*args); end | |
def write(*input); true; end | |
end | |
Rails.application.assets.logger = NullLogger.new | |
class TemporaryLoggerLevel | |
LEVEL = Logger::ERROR | |
def initialize(env) | |
@env = env | |
@initial_level = ::Rails.logger.level | |
end | |
def swap | |
Rails.logger.level = determine_level | |
yield | |
ensure | |
Rails.logger.level = @initial_level | |
end | |
private | |
def determine_level | |
assets_path? ? LEVEL : @initial_level | |
end | |
def assets_path? | |
@env['PATH_INFO'] =~ /^\/assets\// | |
end | |
end | |
class Rails::Rack::Logger | |
alias_method :standard_call, :call | |
def call(env) | |
TemporaryLoggerLevel.new(env).swap do | |
standard_call(env) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment