Class: OmniLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/omni_logger.rb,
lib/omni_logger/version.rb

Constant Summary collapse

LOG_LEVELS =
{
  debug: Logger::Severity::DEBUG,
  info: Logger::Severity::INFO,
  warn: Logger::Severity::WARN,
  fatal: Logger::Severity::FATAL,
  error: Logger::Severity::ERROR
}
VERSION =
"0.1.4"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ OmniLogger

Returns a new instance of OmniLogger.



25
26
27
28
29
30
# File 'lib/omni_logger.rb', line 25

def initialize(args={})
  @loggers = [].concat(OmniLogger.default_loggers)
  self.level = args[:level] || :debug

  Array(args[:loggers]).each { |logger| add_logger(logger) }
end

Class Method Details

.add_default_loggers(*loggers) ⇒ Object



17
18
19
# File 'lib/omni_logger.rb', line 17

def self.add_default_loggers(*loggers)
  default_loggers.concat(loggers)
end

.default_loggersObject



13
14
15
# File 'lib/omni_logger.rb', line 13

def self.default_loggers
  @default_loggers ||= []
end

.reset_default_loggersObject



21
22
23
# File 'lib/omni_logger.rb', line 21

def self.reset_default_loggers
  @default_loggers = []
end

Instance Method Details

#<<(msg) ⇒ Object



54
55
56
# File 'lib/omni_logger.rb', line 54

def <<(msg)
  @loggers.map { |logger| logger << msg }
end

#add(level, *args) ⇒ Object



50
51
52
# File 'lib/omni_logger.rb', line 50

def add(level, *args)
  @loggers.each { |logger| logger.add(level, *args) }
end

#add_logger(logger) ⇒ Object



32
33
34
35
# File 'lib/omni_logger.rb', line 32

def add_logger(logger)
  logger.level = @level
  @loggers << logger
end

#closeObject



46
47
48
# File 'lib/omni_logger.rb', line 46

def close
  @loggers.map(&:close)
end

#levelObject



42
43
44
# File 'lib/omni_logger.rb', line 42

def level
  OmniLogger::LOG_LEVELS.rassoc(@level).first
end

#level=(level_to_log) ⇒ Object



37
38
39
40
# File 'lib/omni_logger.rb', line 37

def level=(level_to_log)
  @level = OmniLogger::LOG_LEVELS.fetch(level_to_log, level_to_log)
  @loggers.each { |logger| logger.level = @level }
end