Sha256: 1a80ee5f1a04abfe6afcf7e6291fb7592f56ee2a5bc4b08a05657892e2585884

Contents?: true

Size: 1.35 KB

Versions: 44

Compression:

Stored size: 1.35 KB

Contents

# To reduce the noise of the SQL logs, this class changes INFO
# logs to DEBUG, and changes the ERROR logs that occur when
# Sequel doesn't know if a table/view exists or not to DEBUG,
# so that they don't freak newbies out when they start up the
# broker for the first time.

require "delegate"

module PactBroker
  module DB
    class LogQuietener < SimpleDelegator
      def error *args
        if error_is_about_table_not_existing?(args)
          __getobj__().debug(*reassure_people_that_this_is_expected(args))
        elsif foreign_key_error?(args)
          __getobj__().warn(*args)
        else
          __getobj__().error(*args)
        end
      end

      def error_is_about_table_not_existing?(args)
        args.first.is_a?(String) &&
          ( args.first.include?("PG::UndefinedTable") ||
            args.first.include?("no such table") ||
            args.first.include?("no such view"))
      end

      # Foreign key exceptions are almost always transitory and unreproducible by this stage
      def foreign_key_error?(args)
        args.first.is_a?(String) && args.first.downcase.include?("foreign key")
      end

      def reassure_people_that_this_is_expected(args)
        message = args.shift
        message = message + " Don't panic. This happens when Sequel doesn't know if a table/view exists or not."
        [message] + args
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.111.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.109.1 lib/pact_broker/db/log_quietener.rb
pact_broker-2.109.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.108.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.107.1 lib/pact_broker/db/log_quietener.rb
pact_broker-2.107.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/db/log_quietener.rb
pact_broker-2.106.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.105.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.104.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.103.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.102.2 lib/pact_broker/db/log_quietener.rb
pact_broker-2.102.1 lib/pact_broker/db/log_quietener.rb
pact_broker-2.102.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.101.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.100.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.99.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.98.0 lib/pact_broker/db/log_quietener.rb
pact_broker-2.97.0 lib/pact_broker/db/log_quietener.rb