diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index de1633a4f7..c4482be990 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -1,9 +1,33 @@ require 'sinatra/base' +require 'sinatra/custom_logger' require 'appsignal/integrations/sinatra' if ENV['APPSIGNAL_ENABLED_FOR_DYNOS']&.split(' ')&.include?(ENV['DYNO']) require 'mustermann' require 'travis/api/app' require 'travis/api/app/extensions' require 'travis/api/app/helpers' +require 'logger' + +class CensoredLogger < ::Logger + def info(message) + super(censor(message)) + end + + def error(message) + super(censor(message)) + end + + def warn(message) + super(censor(message)) + end + + private + + def censor(message) + regex = /token="?'?\w+"?'?/ + '[censored] ' + message.gsub(regex, 'token=<***>') + end +end + class Travis::Api::App # Superclass for any endpoint and middleware. @@ -11,6 +35,7 @@ class Travis::Api::App class Base < Sinatra::Base register Extensions::SmartConstants register Mustermann + helpers Sinatra::CustomLogger error NotImplementedError do content_type :txt @@ -50,6 +75,8 @@ def call(env) disable :logging, :dump_errors end + logger = CensoredLogger.new(File.open('/var/log/travis.log', 'a')) + set :logger, logger register :subclass_tracker, :expose_pattern helpers :respond_with, :mime_types end