class DICOM::Logging::ClassMethods::ProxyLogger

We use our own ProxyLogger to achieve the features wanted for DICOM logging, e.g. using DICOM as progname for messages logged within the DICOM module (for both the Standard logger as well as the Rails logger), while still allowing a custom progname to be used when the logger is called outside the DICOM module.

Public Class Methods

new(target) click to toggle source

Creating the ProxyLogger instance.

@param [Logger] target a logger instance (e.g. Standard Logger or ActiveSupport::BufferedLogger)

# File lib/dicom/general/logging.rb, line 57
def initialize(target)
  @target = target
end

Public Instance Methods

method_missing(method_name, *args) { || ... } click to toggle source

Catches missing methods.

In our case, the methods of interest are the typical logger methods, i.e. log, info, fatal, error, debug, where the arguments/block are redirected to the logger in a specific way so that our stated logger features are achieved (this behaviour depends on the logger (Rails vs Standard) and in the case of Standard logger, whether or not a block is given).

@example Inside the DICOM module or an external class with 'include DICOM::Logging':

logger.info "message"

@example Calling from outside the DICOM module:

DICOM.logger.info "message"
# File lib/dicom/general/logging.rb, line 76
def method_missing(method_name, *args, &block)
  if method_name.to_s =~ /(log|debug|info|warn|error|fatal)/
    # Rails uses it's own buffered logger which does not
    # work with progname + block as the standard logger does:
    if defined?(Rails)
      @target.send(method_name, "DICOM: #{args.first}")
    elsif block_given?
      @target.send(method_name, *args) { yield }
    else
      @target.send(method_name, "DICOM") { args.first }
    end
  else
    @target.send(method_name, *args, &block)
  end
end