Module: RTKIT::Logging::ClassMethods

Defined in:
lib/rtkit/logging.rb

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

#loggerObject

The logger object getter. Returns the logger class variable, if defined. If not defined, sets up the Rails logger (if in a Rails environment), or a Standard logger if not.

Examples

# Inside the RTKIT module (or a class with 'include RTKIT::Logging'):
logger # => Logger instance

# Accessing from outside the RTKIT module:
RTKIT.logger # => Logger instance


132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rtkit/logging.rb', line 132

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.

Parameters

  • l – A Logger instance (e.g. a custom standard Logger).

Examples

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


115
116
117
# File 'lib/rtkit/logging.rb', line 115

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