From 6a09122df204372ae998ca6676212aef8c9096e3 Mon Sep 17 00:00:00 2001 From: Karol Selak Travis Date: Wed, 2 Feb 2022 09:29:25 +0100 Subject: [PATCH] next try --- lib/travis/api/app/base.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index c4482be990..ebb261c2bf 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -28,6 +28,33 @@ def censor(message) end end +module Sinatra + module QuietLogger + + @extensions = %w(png gif jpg jpeg woff tff svg eot css js coffee scss) + + class << self + attr_accessor :extensions + + def registered(app) + ::Rack::CommonLogger.class_eval <<-PATCH + alias call_and_log call + + def call(env) + ext = env['REQUEST_PATH'].split('.').last + if #{extensions.inspect}.include? ext + @app.call(env) + else + call_and_log(env) + end + end + PATCH + end + end + + end +end + class Travis::Api::App # Superclass for any endpoint and middleware. @@ -74,9 +101,8 @@ def call(env) else disable :logging, :dump_errors end + register QuietLogger - logger = CensoredLogger.new(File.open('/var/log/travis.log', 'a')) - set :logger, logger register :subclass_tracker, :expose_pattern helpers :respond_with, :mime_types end