Module: Threatinator::Logger

Defined in:
lib/threatinator/logger.rb

Defined Under Namespace

Modules: Levels

Class Method Summary collapse

Class Method Details

.configure_logger(config) ⇒ Object

Parameters:



27
28
29
30
31
32
33
34
35
# File 'lib/threatinator/logger.rb', line 27

def self.configure_logger(config)
  if config.level
    if l = self.levels.index(config.level)
      default_logger.level = l
    else
      default_logger.warn("Ignoring unknown logging level: #{config.level.inspect}.")
    end
  end
end

.default_loggerObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/threatinator/logger.rb', line 13

def self.default_logger
  return @logger unless @logger.nil?

  @logger = logger_for('Threatinator')
  formatter = ::Log4r::PatternFormatter.new(:pattern => '[%d] %l %C: %M')

  console_outputter = ::Log4r::StderrOutputter.new('console', formatter: formatter)
  @logger.add console_outputter

  @logger.level = ::Log4r::INFO
  @logger
end

.levelObject



37
38
39
# File 'lib/threatinator/logger.rb', line 37

def self.level
  default_logger.level
end

.level=(l) ⇒ Object



41
42
43
# File 'lib/threatinator/logger.rb', line 41

def self.level=(l)
  default_logger.level = l
end

.level_stringObject



45
46
47
# File 'lib/threatinator/logger.rb', line 45

def self.level_string
  levels[level]
end

.levelsObject



49
50
51
# File 'lib/threatinator/logger.rb', line 49

def self.levels
  default_logger.levels
end

.logger_for(name) ⇒ Object



9
10
11
# File 'lib/threatinator/logger.rb', line 9

def self.logger_for(name)
  ::Log4r::Logger[name] || ::Log4r::Logger.new(name)
end