org.symbian.tools.wrttools/projecttemplates/WRTKit/Utils/Logger.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 16 Mar 2010 18:01:11 -0700
changeset 273 b1f63c2c240c
parent 211 7b148352159e
permissions -rw-r--r--
Bug 2072 - Update .js files with EPL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     1
/**
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     2
 * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     3
 * All rights reserved.
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     4
 * This component and the accompanying materials are made available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     6
 * which accompanies this distribution, and is available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     8
 *
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     9
 * Initial Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    10
 * Nokia Corporation - initial contribution.
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    11
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    12
 * Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    13
 * 
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    14
 * Description:
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    15
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    16
 */
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    17
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    18
///////////////////////////////////////////////////////////////////////////////
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    19
// Logger utility class that uses the Firebug console class.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    20
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    21
// Constructor (everything is static so this is empty).
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    22
function Logger() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    23
    // Set default logger level.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    24
    this.level = this.LOG_LEVEL_OFF;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    25
}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    26
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    27
// Logger levels.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    28
Logger.prototype.LOG_LEVEL_DEBUG = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    29
Logger.prototype.LOG_LEVEL_INFO = 1;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    30
Logger.prototype.LOG_LEVEL_WARN = 2;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    31
Logger.prototype.LOG_LEVEL_ERROR = 3;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    32
Logger.prototype.LOG_LEVEL_OFF = 4;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    33
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    34
Logger.prototype.level = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    35
Logger.prototype.filter = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    36
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    37
// Disable logging on other browsers except Firefox.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    38
Logger.prototype.enabled = (navigator.userAgent.indexOf("Firefox") != -1);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    39
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    40
// Dumps an objects properties and methods to the console.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    41
Logger.prototype.dump = function(obj) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    42
    if (this.enabled) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    43
        console.dir(obj);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    44
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    45
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    46
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    47
// Dumps a stracktrace to the console.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    48
Logger.prototype.trace = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    49
    if (this.enabled) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    50
        console.trace();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    51
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    52
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    53
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    54
// Prints a debug message to the console.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    55
Logger.prototype.debug = function(str) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    56
    if (this.enabled && this.level <= this.LOG_LEVEL_DEBUG) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    57
        if (this.filter == null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    58
            console.debug(str);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    59
        } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    60
            var show = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    61
            for (i in this.filter) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    62
                if (str.indexOf(this.filter[i]) >= 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    63
                    show = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    64
                    break;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    65
                }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    66
            }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    67
            if (show) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    68
                console.debug(str);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    69
            }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    70
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    71
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    72
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    74
// Prints an info message to the console.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    75
Logger.prototype.info = function(str) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    76
    if (this.enabled && this.level <= this.LOG_LEVEL_INFO) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    77
        console.info(str);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    78
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    79
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    80
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    81
// Prints a warning message to the console.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    82
Logger.prototype.warn = function(str) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    83
    if (this.enabled && this.level <= this.LOG_LEVEL_WARN) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    84
        console.warn(str);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    85
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    86
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    87
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    88
// Prints an error message to the console.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    89
Logger.prototype.error = function(str) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    90
    if (this.enabled && this.level <= this.LOG_LEVEL_ERROR) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    91
        console.error(str);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    92
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    93
};