Class: UzuUzu::Logger::Loggers

Inherits:
Object
  • Object
show all
Defined in:
lib/uzuuzu-core/logger/loggers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Loggers

Returns a new instance of Loggers.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/uzuuzu-core/logger/loggers.rb', line 11

def initialize(env=nil)
  @adapter = :loggers
  @loggers = []
  unless env
    return
  end
  env.each do |logger_env|
    adapter = logger_env["adapter"]
    require "uzuuzu-core/logger/#{adapter}"
    adapter_class = eval("::UzuUzu::Logger::#{adapter.camel_case}")
    logger = adapter_class.new(logger_env)
    @loggers << logger
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(action, *args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/uzuuzu-core/logger/loggers.rb', line 28

def method_missing(action, *args)
  @loggers.each do |logger|
    begin
      args.each do |message|
        message = message.to_str if message.respond_to?(:to_str)
        message = message.inspect unless message.instance_of?(String)
        logger.send(action, message)
      end
    rescue => e
      # puts standerd error output
      $stderr.puts 'logger unknown error'
      $stderr.puts e
    end
  end
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/uzuuzu-core/logger/loggers.rb', line 7

def adapter
  @adapter
end