lib/watir/logger.rb in watir-6.11.0 vs lib/watir/logger.rb in watir-6.12.0

- old
+ new

@@ -20,30 +20,41 @@ extend Forwardable include ::Logger::Severity def_delegators :@logger, :debug, :debug?, :info, :info?, - :warn, :warn?, + :warn?, :error, :error?, :fatal, :fatal?, :level - def initialize + def initialize(progname="Watir") @logger = create_logger($stdout) + @logger.progname = progname + @ignored = [] end + def ignore(ids) + ids = [ids] unless ids.is_a? Array + @ignored.concat ids.map(&:to_s) + end + def output=(io) - # `Logger#reopen` was added in Ruby 2.3 - if @logger.respond_to?(:reopen) - @logger.reopen(io) - else - @logger = create_logger(io) - end + @logger.reopen(io) end # - # For Ruby < 2.3 compatibility + # Only log a warn message if it is not set to be ignored. + # + def warn(message, ids: [], &block) + msg = ids.empty? ? "" : "[#{ids.map!(&:to_s).map(&:inspect).join(", ")}] " + msg += message + @logger.warn(msg, &block) unless (@ignored & ids).any? + end + + # + # For Ruby < 2.4 compatibility # Based on https://github.com/ruby/ruby/blob/ruby_2_3/lib/logger.rb#L250 # def level=(severity) if severity.is_a?(Integer) @@ -87,11 +98,13 @@ # Marks code as deprecated with replacement. # # @param [String] old # @param [String] new # - def deprecate(old, new) - warn "[DEPRECATION] #{old} is deprecated. Use #{new} instead." + def deprecate(old, new, ids: []) + return if @ignored.include?('deprecations') || (@ignored & ids.map!(&:to_s)).any? + msg = ids.empty? ? "" : "[#{ids.map(&:inspect).join(", ")}] " + warn "[DEPRECATION] #{msg}#{old} is deprecated. Use #{new} instead." end private def create_logger(output)