aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/lib/active_support/logger_thread_safe_level.rb
blob: 4b5f2e7fb3d2d237c5a074d5421c228a50e886f7 (plain) (tree)
1
2
3
4
5
6
7
8
9
                             
                          

                    
                                        


                                 
                                                              






















                                           
# frozen_string_literal: true
require_relative "concern"

module ActiveSupport
  module LoggerThreadSafeLevel # :nodoc:
    extend ActiveSupport::Concern

    def after_initialize
      @local_levels = Concurrent::Map.new(initial_capacity: 2)
    end

    def local_log_id
      Thread.current.__id__
    end

    def local_level
      @local_levels[local_log_id]
    end

    def local_level=(level)
      if level
        @local_levels[local_log_id] = level
      else
        @local_levels.delete(local_log_id)
      end
    end

    def level
      local_level || super
    end
  end
end