class Ditty::Services::Logger

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

Attributes

loggers[R]

Public Class Methods

new() click to toggle source
# 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

Private Class Methods

method_missing(method, *args, &block) click to toggle source
# 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) click to toggle source
Calls superclass method
# File lib/ditty/services/logger.rb, line 67
def respond_to_missing?(method, _include_private)
  return true if instance.respond_to?(method)

  super
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source

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

# File lib/ditty/services/logger.rb, line 35
def method_missing(method, *args, &block)
  loggers.each { |logger| logger.send(method, *args, &block) }
end
respond_to_missing?(method, _include_private = false) click to toggle source
Calls superclass method
# 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

Private Instance Methods

config() click to toggle source
# File lib/ditty/services/logger.rb, line 47
def config
  default.merge ::Ditty::Services::Settings.values(:logger) || {}
end
default() click to toggle source
# File lib/ditty/services/logger.rb, line 58
def default
  { loggers: [{ name: 'default', class: 'Logger' }] }
end
tr(val) click to toggle source
# File lib/ditty/services/logger.rb, line 51
def tr(val)
  {
    '$stdout' => $stdout,
    '$stderr' => $stderr
  }[val] || val
end