Sha256: 494744ad6ead2eb6b4f5ba81499d8797abe45e1e26185fd45ee5b879ff98dfe0

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module ActiveSupport
  # Extracted from:
  # https://github.com/rails/rails/blob/564e427c05e0d3d24ce8c3ab17ea0969011e056a/activesupport/lib/active_support/logger_thread_safe_level.rb
  # Compare SHA with latest commit to check for changes:
  # https://github.com/rails/rails/blob/main/activesupport/lib/active_support/logger_thread_safe_level.rb
  module LoggerThreadSafeLevel # :nodoc:
    extend ActiveSupport::Concern

    def local_level
      IsolatedExecutionState[local_level_key]
    end

    def local_level=(level)
      case level
      when Integer
      when Symbol
        level = Logger::Severity.const_get(level.to_s.upcase)
      when nil
      else
        raise ArgumentError, "Invalid log level: #{level.inspect}"
      end
      if level.nil?
        IsolatedExecutionState.delete(local_level_key)
      else
        IsolatedExecutionState[local_level_key] = level
      end
    end

    def level
      local_level || super
    end

    # Change the thread-local level for the duration of the given block.
    def log_at(level)
      old_local_level, self.local_level = local_level, level
      yield
    ensure
      self.local_level = old_local_level
    end

    private

    def local_level_key
      @local_level_key ||= :"logger_thread_safe_level_#{object_id}"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activesupport-logger-2.0.3 lib/activesupport/logger_thread_safe_level.rb
activesupport-logger-2.0.2 lib/activesupport/logger_thread_safe_level.rb
activesupport-logger-2.0.1 lib/activesupport/logger_thread_safe_level.rb
activesupport-logger-2.0.0 lib/activesupport/logger_thread_safe_level.rb
activesupport-logger-1.0.1 lib/activesupport/logger_thread_safe_level.rb
activesupport-logger-1.0.0 lib/activesupport/logger_thread_safe_level.rb