Class: UzuUzu::Logger::File

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ File

Returns a new instance of File.



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

def initialize(env=nil)
  @adapter = :file
  out = env['path']
  rotate = (env['rotate'] || 0).to_i
  rotate_size = (env['rotate_size'] || 0).to_i * 1024
  ::FileUtils.mkdir_p(::File.dirname(out))
  @logger = ::Logger.new(out, rotate, rotate_size)
  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



38
39
40
41
42
43
44
45
46
# File 'lib/uzuuzu-core/logger/file.rb', line 38

def method_missing(action, *args)
  begin
    @logger.send(action, *args)
  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/file.rb', line 8

def adapter
  @adapter
end