Sha256: c5506dccad73175d5720afe8941e744047631025b0c8100388dad7ae7dcdb00d

Contents?: true

Size: 1.42 KB

Versions: 126

Compression:

Stored size: 1.42 KB

Contents

# :include: rdoc/MDC
#
# == Other Info
# 
# Version:: $Id$
# Author:: Colby Gutierrez-Kraybill <colby(at)astro.berkeley.edu>

require 'monitor'

module Log4r
  MDCNAME = "log4rMDC"
  MDCNAMEMAXDEPTH = "log4rMDCMAXDEPTH"
  $globalMDCLock = Monitor.new

  # See log4r/MDC.rb
  class MDC < Monitor
    private_class_method :new

    def self.check_thread_instance()
      # need to interlock here, so that if
      # another thread is entering this section
      # of code before the main thread does,
      # then the main thread copy of the MDC
      # is setup before then attempting to clone
      # it off
      if ( Thread.current[MDCNAME] == nil ) then
	$globalMDCLock.synchronize do 
	  if ( Thread.main[MDCNAME] == nil ) then
	    Thread.main[MDCNAME] = Hash.new
	  end
	  if ( Thread.current != Thread.main ) then
	    Thread.current[MDCNAME] = Hash.new
	    Thread.main[MDCNAME].each{ |k,v| Thread.current[MDCNAME][k] = v }
	  end
	end
      end
    end

    def self.get( a_key )
      self.check_thread_instance()
      Thread.current[MDCNAME].fetch(a_key, "");
    end

    def self.get_context()
      self.check_thread_instance()
      return Thread.current[MDCNAME].clone
    end

    def self.put( a_key, a_value )
      self.check_thread_instance()
      Thread.current[MDCNAME][a_key] = a_value
    end

    def self.remove( a_key )
      self.check_thread_instance()
      Thread.current[MDCNAME].delete( a_key )
    end
  end
end

Version data entries

126 entries across 88 versions & 16 rubygems

Version Path
depengine-0.0.11 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.10 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.10 etc/isolate/ruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/log4r-1.1.10/lib/log4r/MDC.rb
depengine-0.0.9 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.9 etc/isolate/ruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.8 etc/isolate/ruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.8 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.7 etc/isolate/ruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.7 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.5 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.5 etc/isolate/ruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.4 etc/isolate/ruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.4 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.3 etc/isolate/ruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.3 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.2 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.2 etc/isolate/ruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.1 etc/isolate/ruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb
depengine-0.0.1 etc/isolate/jruby-1.8/gems/log4r-1.1.8/lib/log4r/MDC.rb