Class: UzuUzu::Logger::Stdout

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Stdout

Returns a new instance of Stdout.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/uzuuzu-core/logger/stdout.rb', line 12

def initialize(env=nil)
  @adapter = :stdout
  @logger = ::Logger.new($stdout)
  level = env['level'] || :debug
  case(level.to_sym)
  when :info
    @logger.level = ::Logger::Severity::INFO
  when :warn
    @logger.level = ::Logger::Severity::WARN
  when :error
    @logger.level = ::Logger::Severity::ERROR
  when :fatal
    @logger.level = ::Logger::Severity::FATAL
  when :unknown
    @logger.level = ::Logger::Severity::UNKNOWN
  else
    @logger.level = ::Logger::Severity::DEBUG
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(action, *args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/uzuuzu-core/logger/stdout.rb', line 34

def method_missing(action, *args)
  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

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



8
9
10
# File 'lib/uzuuzu-core/logger/stdout.rb', line 8

def adapter
  @adapter
end