Skip to content

Commit

Permalink
try with Sinatra logger
Browse files Browse the repository at this point in the history
  • Loading branch information
karoltravis committed Feb 2, 2022
1 parent f2ee36b commit c8b85d7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/travis/api/app/base.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
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.
# Pulls in relevant helpers and extensions.
class Base < Sinatra::Base
register Extensions::SmartConstants
register Mustermann
helpers Sinatra::CustomLogger

error NotImplementedError do
content_type :txt
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c8b85d7

Please sign in to comment.