Module: DICOM::Logging::ClassMethods

Defined in:
lib/dicom/general/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 DICOM module (or a class with ‘include DICOM::Logging’):

logger # => Logger instance

Accessing from outside the DICOM module:

DICOM.logger # => Logger instance

Returns:



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/dicom/general/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:
DICOM.logger = Logger.new('foo.log', 10, 1024000)

Parameters:

  • l (Logger)

    a logger instance



136
137
138
# File 'lib/dicom/general/logging.rb', line 136

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