Module: RTP::Logging

Included in:
RTP, Plan
Defined in:
lib/rtp-connect/logging.rb

Overview

This module handles logging functionality.

Logging functionality uses the Standard library’s Logger class. To properly handle progname, which inside the RTP module is simply “RTP”, in all cases, we use an implementation with a proxy class.

Examples

require 'rtp-connect'
include RTP

# Logging to STDOUT with DEBUG level:
RTP.logger = Logger.new(STDOUT)
RTP.logger.level = Logger::DEBUG

# Logging to a file:
RTP.logger = Logger.new('my_logfile.log')

# Combine an external logger with RTP:
logger = Logger.new(STDOUT)
logger.progname = "MY_APP"
RTP.logger = logger
# Now you can call the logger in the following ways:
RTP.logger.info "Message"               # => "RTP: Message"
RTP.logger.info("MY_MODULE) {"Message"} # => "MY_MODULE: Message"
logger.info "Message"                     # => "MY_APP: Message"

For more information, please read the Standard library Logger documentation.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Inclusion hook to make the ClassMethods available to whatever includes the Logging module, i.e. the RTP module.



39
40
41
# File 'lib/rtp-connect/logging.rb', line 39

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#loggerObject

A logger object getter. Forwards the call to the logger class method of the Logging module.



149
150
151
# File 'lib/rtp-connect/logging.rb', line 149

def logger
  self.class.logger
end