Class: ItunesController::ItunesControllerLogging

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

Constant Summary collapse

DEBUG =
1
INFO =
2
WARN =
3
ERROR =
4
@@logFile =

The log file, if defined then logging opertions will be sent to this file

nil
@@logLevel =
INFO

Class Method Summary collapse

Class Method Details

.debug(msg) ⇒ Object

Used to print logging information at debug level

Parameters:

  • msg (String)

    The message to print



79
80
81
82
83
84
# File 'lib/itunesController/logging.rb', line 79

def self.debug(msg)
    if @@logLevel <= DEBUG
        msg="DEBUG:"+msg
        printMsg(msg)
    end
end

.error(msg, exception = nil) ⇒ Object

Used to print logging information at debug level

Parameters:

  • msg (String)

    The message to print

  • exception (defaults to: nil)

    If not nil then this exception detials will be printed



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/itunesController/logging.rb', line 89

def self.error(msg,exception=nil)
    if @@logLevel <= ERROR
        msg="ERROR:"+msg
        printMsg(msg,true)        
        if (exception!=nil)                
            printMsg("     - #{exception.message}",true)
            exception.backtrace.each do | line |
                printMsg("     * #{line}",true)
            end
        end
    end       
end

.info(msg) ⇒ Object

Used to print logging information at info level

Parameters:

  • msg (String)

    The message to print



63
64
65
66
67
# File 'lib/itunesController/logging.rb', line 63

def self.info(msg)
    if @@logLevel <= INFO            
        printMsg(msg)
    end
end

.setLogFile(file) ⇒ Object

Used to set the location of the log file

Parameters:

  • file (String)

    The log file location



36
37
38
# File 'lib/itunesController/logging.rb', line 36

def self.setLogFile(file)
    @@logFile = file 
end

.setLogLevel(level) ⇒ Object

Use to set the loggin level

Parameters:

  • level (Number)

    The logging level



42
43
44
# File 'lib/itunesController/logging.rb', line 42

def self.setLogLevel(level)
    @@logLevel = level
end

.setLogLevelFromString(level) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/itunesController/logging.rb', line 46

def self.setLogLevelFromString(level)
    if (level=="DEBUG")
        @@logLevel = DEBUG
    elsif (level=="INFO")
        @@logLevel = INFO
    elsif (level=="WARN")
        @@logLevel = WARN
    elsif (level=="ERROR")
        @@logLevel = ERROR
    else
        error("Unkown log configuration '#{level}'")
        exit(1)
    end
end

.warn(msg) ⇒ Object

Used to print logging information at warn level

Parameters:

  • msg (String)

    The message to print



71
72
73
74
75
# File 'lib/itunesController/logging.rb', line 71

def self.warn(msg)
    if @@logLevel <= WARN            
        printMsg(msg)
    end
end