Class: AuthorizeNet::API::Log
- Inherits:
-
Object
- Object
- AuthorizeNet::API::Log
- Defined in:
- lib/authorize_net/api/LogHelper.rb
Constant Summary collapse
- @@shouldLog =
false
- @@loglevels =
['debug','info','warn','error']
Instance Method Summary collapse
- #debug(message) ⇒ Object
- #error(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize ⇒ Log
constructor
A new instance of Log.
- #LogLevelMapper(loglevel) ⇒ Object
- #warn(message) ⇒ Object
Constructor Details
#initialize ⇒ Log
Returns a new instance of Log.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 |
Instance Method Details
#debug(message) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/authorize_net/api/LogHelper.rb', line 42 def debug() if(@@shouldLog) begin @logger.debug rescue Exception => ex ex end end end |
#error(message) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/authorize_net/api/LogHelper.rb', line 69 def error() if(@@shouldLog) begin @logger.error rescue Exception => ex ex end end end |
#info(message) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/authorize_net/api/LogHelper.rb', line 51 def info() if(@@shouldLog) begin @logger.info rescue Exception => ex ex end end end |
#LogLevelMapper(loglevel) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# 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 |
#warn(message) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/authorize_net/api/LogHelper.rb', line 60 def warn() if(@@shouldLog) begin @logger.warn rescue Exception => ex ex end end end |