class AuthorizeNet::API::Log

Public Class Methods

new() click to toggle source
# File lib/authorize_net/api/LogHelper.rb, line 9
def initialize()
    begin   
        filepath = './LogConfig.yml'
        if(File.file?(filepath))
            cnf = YAML::load(File.open(filepath))
            if(@@loglevels.include? cnf['loglevel'].downcase)
                    @@shouldLog = true
                    @logger = Logger.new(cnf['filepath'])
                    @logger.level = LogLevelMapper(cnf['loglevel'].downcase)
                    if(cnf['maskSensitiveData'])
                        @logger.formatter = SensitiveDataFilter.new 
                    else
                          constants = YAML.load_file(File.dirname(__FILE__) + "/constants.yml")
                          @logger.formatter = proc do |severity, datetime, progname, msg|
                          progname = constants['clientId']
                          date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
                          if severity == "INFO" or severity == "WARN"
                          "[#{date_format}] #{severity}  (#{progname}): #{msg}\n"
                          else        
                          "[#{date_format}] #{severity} (#{progname}): #{msg}\n"
                          end
                       end
                    end
            else
                raise "Invalid log levels"
            end
        else
            @@shouldLog = false
        end
    rescue
            @@shouldLog = false
    end
end

Public Instance Methods

LogLevelMapper(loglevel) click to toggle source
# File lib/authorize_net/api/LogHelper.rb, line 78
def LogLevelMapper(loglevel)
    case loglevel
    when 'debug'
                    Logger::DEBUG
            when 'info'
                    Logger::INFO
            when 'warn'
                    Logger::WARN
            when 'error'
                    Logger::ERROR
            end
end
debug(message) click to toggle source
# File lib/authorize_net/api/LogHelper.rb, line 42
def debug(message)
    if(@@shouldLog)
         begin
            @logger.debug message
         rescue Exception => ex
            ex
         end
    end
end
error(message) click to toggle source
# File lib/authorize_net/api/LogHelper.rb, line 69
def error(message)
    if(@@shouldLog)
         begin
            @logger.error message
         rescue Exception => ex
            ex
         end
    end
end
info(message) click to toggle source
# File lib/authorize_net/api/LogHelper.rb, line 51
def info(message)
    if(@@shouldLog)
         begin 
            @logger.info message
         rescue Exception => ex
            ex
         end 
    end
end
warn(message) click to toggle source
# File lib/authorize_net/api/LogHelper.rb, line 60
def warn(message)
    if(@@shouldLog)
         begin
            @logger.warn message
         rescue Exception => ex
            ex
         end
    end
end