Class: OmniLogger
- Inherits:
-
Object
- Object
- OmniLogger
- 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
- #<<(msg) ⇒ Object
- #add(level, *args) ⇒ Object
- #add_logger(logger) ⇒ Object
- #close ⇒ Object
-
#initialize(args = {}) ⇒ OmniLogger
constructor
A new instance of OmniLogger.
- #level ⇒ Object
- #level=(level_to_log) ⇒ Object
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_loggers ⇒ Object
13 14 15 |
# File 'lib/omni_logger.rb', line 13 def self.default_loggers @default_loggers ||= [] end |
.reset_default_loggers ⇒ Object
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 |
#close ⇒ Object
46 47 48 |
# File 'lib/omni_logger.rb', line 46 def close @loggers.map(&:close) end |
#level ⇒ Object
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 |