Module: Eco::Language::AuxiliarLogger

Overview

Some modules/classes use logger, but they may not be connected to session. This prevents errors with this.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

Provides either an available logger or a basic one



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/eco/language/auxiliar_logger.rb', line 9

def logger
  if instance_variable_defined?(:@session) && !@session.nil?
    @session.logger
  elsif respond_to?(:session)
    session.logger
  elsif Object.const_defined?(:ASSETS)
    ASSETS.session.logger
  elsif defined?(super)
    super
  else
    @logger ||= Eco::Language::BasicLogger.new
  end
end

Instance Method Details

#log(*levels, &block) ⇒ NilClass

TODO:

allow for more channels (atm it's just :general )

Note:

when :general is included, it ensures at least :info level is also logged.

Shortcut to logger.

Returns:

  • (NilClass)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/eco/language/auxiliar_logger.rb', line 28

def log(*levels, &block)
  return unless logger

  levels = levels.compact.uniq.map(&:to_sym)
  levels.unshift(:info) if levels.include?(:general) && levels.length == 1

  levels.each do |level|
    next unless logger.respond_to?(:level)

    logger.send(level, &block)
  end

  nil
end