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

TODO: REfac this so that you can log something like ES to a separate logger



35
36
37
# File 'lib/ditty/services/logger.rb', line 35

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



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

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

.respond_to_missing?(method, _include_private) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/ditty/services/logger.rb', line 67

def respond_to_missing?(method, _include_private)
  return true if instance.respond_to?(method)

  super
end

Instance Method Details

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

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/ditty/services/logger.rb', line 39

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

  super
end