Class: Ditty::Services::Logger

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ditty/services/logger.rb

Overview

This is the central logger for Ditty. It can be configured to log to multiple endpoints through Ditty Settings. The default configuration is to send logs to $stdout

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ditty/services/logger.rb', line 20

def initialize
  @loggers = []
  return if config[:loggers].blank?

  config[:loggers].each do |values|
    klass = values[:class].constantize
    opts = tr(values[:options]) || nil
    logger = klass.new(opts)
    logger.level = klass.const_get(values[:level].to_sym) if values[:level]
    @loggers << logger
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



33
34
35
# File 'lib/ditty/services/logger.rb', line 33

def method_missing(method, *args, &block)
  loggers.each { |logger| logger.send(method, *args, &block) }
end

Instance Attribute Details

#loggersObject (readonly)

Returns the value of attribute loggers.



18
19
20
# File 'lib/ditty/services/logger.rb', line 18

def loggers
  @loggers
end

Class Method Details

.method_missing(method, *args, &block) ⇒ Object



59
60
61
# File 'lib/ditty/services/logger.rb', line 59

def method_missing(method, *args, &block)
  instance.send(method, *args, &block)
end

.respond_to_missing?(method, _include_private) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/ditty/services/logger.rb', line 63

def respond_to_missing?(method, _include_private)
  instance.respond_to? method
end

Instance Method Details

#respond_to_missing?(method, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(method, _include_private = false)
  loggers.any? { |logger| logger.respond_to?(method) }
end