Class: Redisk::Logger

Inherits:
Object
  • Object
show all
Extended by:
Helper
Includes:
Helper
Defined in:
lib/redisk/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

redis, redis=

Constructor Details

#initialize(name, options = {}) ⇒ Logger

Returns a new instance of Logger.



9
10
11
12
13
14
# File 'lib/redisk/logger.rb', line 9

def initialize(name, options = {})
  @name     = name
  @io       = Redisk::IO.new(name)
  @truncate = options.delete(:truncate) || false
  @logger   = ::Logger.new(@io, options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

delegate to logger



25
26
27
28
29
30
31
32
33
# File 'lib/redisk/logger.rb', line 25

def method_missing(meth, *args)
  if @logger.respond_to?(meth)
    returned = @logger.send(meth, *args)
    truncate!
    returned
  else
    super
  end
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



7
8
9
# File 'lib/redisk/logger.rb', line 7

def io
  @io
end

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/redisk/logger.rb', line 7

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/redisk/logger.rb', line 7

def name
  @name
end

Instance Method Details

#lengthObject



16
17
18
# File 'lib/redisk/logger.rb', line 16

def length
  @io.length
end

#truncate!Object



20
21
22
# File 'lib/redisk/logger.rb', line 20

def truncate!
  @io.truncate(@truncate) if @truncate && length > @truncate
end