Class: Loggr::SLF4J::MDCWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/loggr/slf4j/mdc.rb

Overview

Wrapper around the SLF4J MDC.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(impl = Java::OrgSlf4j::MDC) ⇒ MDCWrapper

Create a new SLF4J MDC with the supplied implementation.



12
13
14
# File 'lib/loggr/slf4j/mdc.rb', line 12

def initialize(impl = Java::OrgSlf4j::MDC)
  @java_mdc = impl
end

Instance Attribute Details

#java_mdcObject

Access the original SLF4J MDC



9
10
11
# File 'lib/loggr/slf4j/mdc.rb', line 9

def java_mdc
  @java_mdc
end

Instance Method Details

#[](key) ⇒ Object

Read a key from the MDC.



17
# File 'lib/loggr/slf4j/mdc.rb', line 17

def [](key); java_mdc.get(key.to_s) end

#[]=(key, value) ⇒ Object

Write a value to the MDC.



20
# File 'lib/loggr/slf4j/mdc.rb', line 20

def []=(key, value); java_mdc.put(key.to_s, value.to_s) end

#clearObject

Clear all keys from the MDC.



26
# File 'lib/loggr/slf4j/mdc.rb', line 26

def clear; java_mdc.clear() end

#delete(key) ⇒ Object

Remove a key from the MDC.



23
# File 'lib/loggr/slf4j/mdc.rb', line 23

def delete(key); java_mdc.remove(key.to_s) end

#to_hashObject

Convert MDC to a real hash.



29
# File 'lib/loggr/slf4j/mdc.rb', line 29

def to_hash; java_mdc.getCopyOfContextMap().freeze end