Class: Log
- Inherits:
-
Object
- Object
- Log
- Defined in:
- lib/AuthenticationSDK/logging/log_factory.rb
Overview
Logger Class
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(logConfiguration, callingProgram = '') ⇒ Log
constructor
A new instance of Log.
Constructor Details
#initialize(logConfiguration, callingProgram = '') ⇒ Log
Returns a new instance of Log.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/AuthenticationSDK/logging/log_factory.rb', line 10 def initialize(logConfiguration, callingProgram = '') enableLog = logConfiguration.enableLog loggingLevel = logConfiguration.loggingLevel logDirectory = logConfiguration.logDirectory logFilename = logConfiguration.logFilename maxLogSize = logConfiguration.maxLogSize maxLogFiles = logConfiguration.maxLogFiles enableMasking = logConfiguration.enableMasking callingProgram = "Generic" if callingProgram.nil? || callingProgram.empty? #log if enableLog == true filename = File.join logDirectory, logFilename + '.log' # logDirectory + '/' + logFilename + '.log' datetime = DateTime.now if File.exist?(logDirectory) if File.exist?(logFilename) if File.size(filename) >= maxLogSize updatedFileName = File.join logDirectory, logFilename + '_' + datetime.strftime('%Y%m%d%H%M%S') + '.log' File.rename(filename, updatedFileName) end end elsif !File.exist?(logDirectory) FileUtils.mkdir_p logDirectory File.new(filename, "w") end STDOUT.sync = true @logger = Logger.new(STDOUT, progname: callingProgram) @logger = Logger.new(filename, shift_age = maxLogFiles, shift_size = maxLogSize, progname: callingProgram) @logger.level = loggingLevel @logger.datetime_format = datetime.strftime('%Y-%m-%d %H:%M:%S') if enableMasking @logger.formatter = SensitiveDataFilter.new else @logger.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") = "[#{date_format}] #{severity.ljust(10)} (#{progname}): #{msg}\n" # $stdout.puts log_message end end else @logger = Logger.new(false) end rescue StandardError => err # puts err raise err # exit! end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
63 64 65 |
# File 'lib/AuthenticationSDK/logging/log_factory.rb', line 63 def logger @logger end |