Module: EXEL::Logging

Defined in:
lib/exel/logging.rb,
lib/exel/logging/logger_wrapper.rb

Defined Under Namespace

Classes: LoggerWrapper, PrefixFormatter

Constant Summary collapse

DEFAULT_LEVEL =
:info

Class Method Summary collapse

Class Method Details

.initialize_loggerObject


20
21
22
23
24
25
# File 'lib/exel/logging.rb', line 20

def self.initialize_logger
  @logger = Logger.new(log_filename)
  @logger.level = log_level
  @logger.formatter = PrefixFormatter.new
  @logger
end

.log_filenameObject


27
28
29
# File 'lib/exel/logging.rb', line 27

def self.log_filename
  EXEL.configuration.log_filename || '/dev/null'
end

.log_levelObject


31
32
33
34
# File 'lib/exel/logging.rb', line 31

def self.log_level
  level = EXEL.configuration.log_level || DEFAULT_LEVEL
  Logger.const_get(level.to_s.upcase)
end

.loggerObject


16
17
18
# File 'lib/exel/logging.rb', line 16

def self.logger
  @logger || initialize_logger
end

.logger=(logger) ⇒ Object


36
37
38
# File 'lib/exel/logging.rb', line 36

def self.logger=(logger)
  @logger = logger ? LoggerWrapper.new(logger) : Logger.new('/dev/null')
end

.prefixObject


49
50
51
# File 'lib/exel/logging.rb', line 49

def self.prefix
  Thread.current[:exel_log_prefix]&.last
end

.with_prefix(prefix) ⇒ Object

Sets a prefix to be added to any messages sent to the EXEL logger in the given block.


41
42
43
44
45
46
47
# File 'lib/exel/logging.rb', line 41

def self.with_prefix(prefix)
  Thread.current[:exel_log_prefix] ||= []
  Thread.current[:exel_log_prefix].push(prefix)
  yield
ensure
  Thread.current[:exel_log_prefix].pop
end