Module: RTP::Logging::ClassMethods

Defined in:
lib/rtp-connect/logging.rb

Overview

Class methods which the Logging module is extended with.

Defined Under Namespace

Classes: ProxyLogger

Constant Summary collapse

@@logger =

The logger class variable (must be initialized before it is referenced by the object setter).

nil

Instance Method Summary collapse

Instance Method Details

#loggerProxyLogger

The logger object getter.

If a logger instance is not pre-defined, it sets up a Standard logger or (if in a Rails environment) the Rails logger.

Examples:

Inside the RTP module (or a class with ‘include RTP::Logging’):

logger # => Logger instance

Accessing from outside the RTP module:

RTP.logger # => Logger instance

Returns:



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/rtp-connect/logging.rb', line 112

def logger
  @@logger ||= lambda {
    if defined?(Rails)
      ProxyLogger.new(Rails.logger)
    else
      l = Logger.new(STDOUT)
      l.level = Logger::INFO
      ProxyLogger.new(l)
    end
  }.call
end

#logger=(l) ⇒ Object

The logger object setter. This method is used to replace the default logger instance with a custom logger of your own.

Examples:

Multiple log files

# Create a logger which ages logfile once it reaches a certain size,
# leaving 10 "old log files" with each file being about 1,024,000 bytes:
RTP.logger = Logger.new('foo.log', 10, 1024000)

Parameters:

  • l (Logger)

    a logger instance



135
136
137
# File 'lib/rtp-connect/logging.rb', line 135

def logger=(l)
  @@logger = ProxyLogger.new(l)
end