Module: Cosmo::Logger::Context

Defined in:
lib/cosmo/logger.rb,
sig/cosmo/logger.rbs

Constant Summary collapse

KEY =

Returns:

  • (Symbol)
:cosmo_context

Class Method Summary collapse

Class Method Details

.currentHash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


26
27
28
29
# File 'lib/cosmo/logger.rb', line 26

def self.current
  Thread.current[KEY] ||= {}
  Thread.current[KEY]
end

.with(**options) ⇒ void

This method returns an undefined value.

Parameters:

  • options (Object)


13
14
15
16
17
18
19
# File 'lib/cosmo/logger.rb', line 13

def self.with(**options)
  prev = current
  Thread.current[KEY] = prev.merge(options)
  yield if block_given?
ensure
  Thread.current[KEY] = prev if block_given?
end

.without(*keys) ⇒ nil

Parameters:

  • keys (Symbol)

Returns:

  • (nil)


21
22
23
24
# File 'lib/cosmo/logger.rb', line 21

def self.without(*keys)
  Thread.current[KEY] = current.except(*keys)
  nil
end