Class: LogJam::Logger

Inherits:
Logger
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/logjam/logger.rb

Overview

This class represents a specialization of the Ruby Logger class. The class retains a Ruby Logger instance within itself and delegates all standard logger calls to this instance. This allows for changes to the underlying logger without changing the containing one, thus bypassing people caching an instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logdev, shift_age = 0, shift_size = 1048576) ⇒ Logger

Constructor for the Logger class. All parameters are passed straight through to create a standard Ruby Logger instance except when the first parameter is a Logger instance. In this case the Logger passed in is used rather than creating a new one.

Parameters

logdev

The log device to be used by the logger. This should be be a String containing a file path/name, an IO object that the logging details will be written to or another logger that you want to wrap.

shift_age

The maximum number of old log files to retain or a String containing the rotation frequency for the log.

shift_size

The maximum size that the logging output will be allowed to grow to before rotation occurs.



34
35
36
37
# File 'lib/logjam/logger.rb', line 34

def initialize(logdev, shift_age=0, shift_size=1048576)
  @log = (logdev.kind_of?(::Logger) ? logdev : ::Logger.new(logdev, shift_age, shift_size))
  @name = nil
end

Instance Attribute Details

#nameObject

Attribute accessor/mutator declaration.



40
41
42
# File 'lib/logjam/logger.rb', line 40

def name
  @name
end

Instance Method Details

#loggerObject

This method fetches the standard Ruby Logger instance contained within a Logger object.



44
45
46
# File 'lib/logjam/logger.rb', line 44

def logger
  @log
end

#logger=(logger) ⇒ Object

This method updates the logger instance contained within a Logger object.

Parameters

logger

The object to set as the contained logger. This should be an instance of the standard Ruby Logger class or something compatible with this.



55
56
57
# File 'lib/logjam/logger.rb', line 55

def logger=(logger)
  @log = logger
end