Class: LogConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/AuthenticationSDK/logging/log_configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_config) ⇒ LogConfiguration

Returns a new instance of LogConfiguration.



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
62
63
64
65
66
67
68
69
70
# File 'lib/AuthenticationSDK/logging/log_configuration.rb', line 14

def initialize(log_config)
        @enableLog = log_config['enableLog']
        @loggingLevel = log_config['loggingLevel']
        @logDirectory = log_config['logDirectory']
        @logFilename = log_config['logFilename']
        @maxLogSize = log_config['maxLogSize']
        @maxLogFiles = log_config['maxLogFiles']
        @enableMasking = log_config['enableMasking']

    def validate(log_message)
        if @enableLog == "true"
            @enableLog = true
        elsif @enableLog == true
            @enableLog = true
        else
            @enableLog = false
        end
        if @enableLog
            if !Constants::LOG_LEVELS.include? @loggingLevel
                @loggingLevel = Constants::DEFAULT_LOG_LEVEL
                log_message += Constants::WARNING_PREFIX + Constants::INVALID_LOG_LEVEL + @loggingLevel
            end
            if @logDirectory.to_s.empty? # || !Dir.exist?(@logDirectory)
                @logDirectory = Constants::DEFAULT_LOG_DIRECTORY
                unless Dir.exist?(@logDirectory)
                    Dir.mkdir(Constants::DEFAULT_LOG_DIRECTORY)
                end
                log_message += Constants::WARNING_PREFIX + Constants::INVALID_LOG_DIRECTORY + File.expand_path(@logDirectory)
            end
            if @logFilename.to_s.empty?
                @logFilename = Constants::DEFAULT_LOGFILE_NAME
            elsif !@logFilename.instance_of? String
                @logFilename = @logFilename.to_s
            end
            if @maxLogSize.nil? || @maxLogSize.to_s.empty?
                @maxLogSize = Constants::DEFAULT_LOG_SIZE
                log_message += Constants::WARNING_PREFIX + Constants::INVALID_MAX_LOG_SIZE + @maxLogSize
            elsif !@maxLogSize.instance_of? Integer
                @maxLogSize = @maxLogSize.to_i
            end
            if @maxLogFiles.nil? || @maxLogFiles.to_s.empty?
                @maxLogFiles = Constants::DEFAULT_MAX_LOG_FILES
                log_message += Constants::WARNING_PREFIX + Constants::INVALID_MAX_LOG_FILES + @maxLogFiles
            elsif !@maxLogFiles.instance_of? Integer
                @maxLogFiles = @maxLogFiles.to_i
            end
            if @enableMasking == "true"
                @enableMasking = true
            elsif @enableMasking == true
                @enableMasking = true
            else
                @enableMasking = false
            end
        end
        return log_message
    end
end

Instance Attribute Details

#enableLogObject

Setter/Getter



6
7
8
# File 'lib/AuthenticationSDK/logging/log_configuration.rb', line 6

def enableLog
  @enableLog
end

#enableMaskingObject

Returns the value of attribute enableMasking.



12
13
14
# File 'lib/AuthenticationSDK/logging/log_configuration.rb', line 12

def enableMasking
  @enableMasking
end

#logDirectoryObject

Returns the value of attribute logDirectory.



8
9
10
# File 'lib/AuthenticationSDK/logging/log_configuration.rb', line 8

def logDirectory
  @logDirectory
end

#logFilenameObject

Returns the value of attribute logFilename.



9
10
11
# File 'lib/AuthenticationSDK/logging/log_configuration.rb', line 9

def logFilename
  @logFilename
end

#loggingLevelObject

Returns the value of attribute loggingLevel.



7
8
9
# File 'lib/AuthenticationSDK/logging/log_configuration.rb', line 7

def loggingLevel
  @loggingLevel
end

#maxLogFilesObject

Returns the value of attribute maxLogFiles.



11
12
13
# File 'lib/AuthenticationSDK/logging/log_configuration.rb', line 11

def maxLogFiles
  @maxLogFiles
end

#maxLogSizeObject

Returns the value of attribute maxLogSize.



10
11
12
# File 'lib/AuthenticationSDK/logging/log_configuration.rb', line 10

def maxLogSize
  @maxLogSize
end

Instance Method Details

#validate(log_message) ⇒ Object



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
62
63
64
65
66
67
68
69
# File 'lib/AuthenticationSDK/logging/log_configuration.rb', line 23

def validate(log_message)
    if @enableLog == "true"
        @enableLog = true
    elsif @enableLog == true
        @enableLog = true
    else
        @enableLog = false
    end
    if @enableLog
        if !Constants::LOG_LEVELS.include? @loggingLevel
            @loggingLevel = Constants::DEFAULT_LOG_LEVEL
            log_message += Constants::WARNING_PREFIX + Constants::INVALID_LOG_LEVEL + @loggingLevel
        end
        if @logDirectory.to_s.empty? # || !Dir.exist?(@logDirectory)
            @logDirectory = Constants::DEFAULT_LOG_DIRECTORY
            unless Dir.exist?(@logDirectory)
                Dir.mkdir(Constants::DEFAULT_LOG_DIRECTORY)
            end
            log_message += Constants::WARNING_PREFIX + Constants::INVALID_LOG_DIRECTORY + File.expand_path(@logDirectory)
        end
        if @logFilename.to_s.empty?
            @logFilename = Constants::DEFAULT_LOGFILE_NAME
        elsif !@logFilename.instance_of? String
            @logFilename = @logFilename.to_s
        end
        if @maxLogSize.nil? || @maxLogSize.to_s.empty?
            @maxLogSize = Constants::DEFAULT_LOG_SIZE
            log_message += Constants::WARNING_PREFIX + Constants::INVALID_MAX_LOG_SIZE + @maxLogSize
        elsif !@maxLogSize.instance_of? Integer
            @maxLogSize = @maxLogSize.to_i
        end
        if @maxLogFiles.nil? || @maxLogFiles.to_s.empty?
            @maxLogFiles = Constants::DEFAULT_MAX_LOG_FILES
            log_message += Constants::WARNING_PREFIX + Constants::INVALID_MAX_LOG_FILES + @maxLogFiles
        elsif !@maxLogFiles.instance_of? Integer
            @maxLogFiles = @maxLogFiles.to_i
        end
        if @enableMasking == "true"
            @enableMasking = true
        elsif @enableMasking == true
            @enableMasking = true
        else
            @enableMasking = false
        end
    end
    return log_message
end