Sha256: b2edfdc233e8bf0ee5fdf9c0199ef70c651378b6f8a70a424b8925b39cf72272

Contents?: true

Size: 1.15 KB

Versions: 16

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "active_support/logger_silence"
require "active_support/logger_thread_safe_level"
require "logger"

module ActiveSupport
  class Logger < ::Logger
    include LoggerSilence

    # Returns true if the logger destination matches one of the sources
    #
    #   logger = Logger.new(STDOUT)
    #   ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
    #   # => true
    def self.logger_outputs_to?(logger, *sources)
      loggers = if logger.is_a?(BroadcastLogger)
        logger.broadcasts
      else
        [logger]
      end

      logdevs = loggers.map { |logger| logger.instance_variable_get(:@logdev) }
      logger_sources = logdevs.filter_map { |logdev| logdev.dev if logdev.respond_to?(:dev) }

      (sources & logger_sources).any?
    end

    def initialize(*args, **kwargs)
      super
      @formatter ||= SimpleFormatter.new
    end

    # Simple formatter which only displays the message.
    class SimpleFormatter < ::Logger::Formatter
      # This method is invoked when a log event occurs
      def call(severity, timestamp, progname, msg)
        "#{String === msg ? msg : msg.inspect}\n"
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 5 rubygems

Version Path
activesupport-7.1.5 lib/active_support/logger.rb
activesupport-7.1.4.2 lib/active_support/logger.rb
activesupport-7.1.4.1 lib/active_support/logger.rb
activesupport-7.1.4 lib/active_support/logger.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/logger.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/logger.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/logger.rb
activesupport-7.1.3.4 lib/active_support/logger.rb
activesupport-7.1.3.2 lib/active_support/logger.rb
activesupport-7.1.3.1 lib/active_support/logger.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3/lib/active_support/logger.rb
activesupport-7.1.3 lib/active_support/logger.rb
activesupport-7.1.2 lib/active_support/logger.rb
activesupport-7.1.1 lib/active_support/logger.rb
activesupport-7.1.0 lib/active_support/logger.rb
activesupport-7.1.0.rc2 lib/active_support/logger.rb