Class: Log4r::MDC

Inherits:
Monitor
  • Object
show all
Defined in:
lib/log4r/MDC.rb

Overview

See log4r/MDC.rb

Class Method Summary collapse

Class Method Details

.check_thread_instanceObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/log4r/MDC.rb', line 19

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

.get(a_key) ⇒ Object



39
40
41
42
# File 'lib/log4r/MDC.rb', line 39

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

.get_contextObject



44
45
46
47
# File 'lib/log4r/MDC.rb', line 44

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

.put(a_key, a_value) ⇒ Object



49
50
51
52
# File 'lib/log4r/MDC.rb', line 49

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

.remove(a_key) ⇒ Object



54
55
56
57
# File 'lib/log4r/MDC.rb', line 54

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