1 // ========================================================================== 2 // Project: The M-Project - Mobile HTML5 Application Framework 3 // Copyright: (c) 2010 M-Way Solutions GmbH. All rights reserved. 4 // (c) 2011 panacoda GmbH. All rights reserved. 5 // Creator: Dominik 6 // Date: 26.10.2010 7 // License: Dual licensed under the MIT or GPL Version 2 licenses. 8 // http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE 9 // http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE 10 // ========================================================================== 11 12 m_require('core/foundation/request.js'); 13 14 /** 15 * A constant value for logging level: info. 16 * 17 * @type Number 18 */ 19 M.INFO = 0; 20 21 /** 22 * A constant value for logging level: debug. 23 * 24 * @type Number 25 */ 26 M.DEBUG = 1; 27 28 /** 29 * A constant value for logging level: warning. 30 * 31 * @type Number 32 */ 33 M.WARN = 2; 34 35 /** 36 * A constant value for logging level: error. 37 * 38 * @type Number 39 */ 40 M.ERR = 3; 41 42 /** 43 * @class 44 * 45 * M.Logger defines the prototype for any logging object. It is used to log messages out of the application 46 * based on a given logging level. 47 * 48 * @extends M.Object 49 */ 50 M.Logger = M.Object.extend( 51 /** @scope M.Logger.prototype */ { 52 53 /** 54 * The type of this object. 55 * 56 * @type String 57 */ 58 type: 'M.Logger', 59 60 /** 61 * This method is used to log anything out of an application based on the given logging level. 62 * Possible values for the logging level are: 63 * 64 * - debug: M.DEBUG 65 * - error: M.ERROR 66 * - warning: M.WARN 67 * - info: M.INFO 68 * 69 * @param {String} msg The logging message. 70 * @param {Number} level The logging level. 71 */ 72 log: function(msg, level) { 73 level = level || M.DEBUG; 74 75 /* are we in production mode, then do not throw any logs */ 76 if(M.Application.getConfig('debugMode') === 'false') { 77 return; 78 } 79 80 /* Prevent a console.log from blowing things up if we are on a browser that doesn't support this. */ 81 if (typeof console === 'undefined') { 82 window.console = {} ; 83 console.log = console.info = console.warn = console.error = function(){}; 84 } 85 86 switch (level) { 87 case M.DEBUG: 88 this.debug(msg); 89 break; 90 case M.ERR: 91 this.error(msg); 92 break; 93 case M.WARN: 94 this.warn(msg); 95 break; 96 case M.INFO: 97 this.info(msg); 98 break; 99 default: 100 this.debug(msg); 101 break; 102 } 103 }, 104 105 /** 106 * This method is used to log a message on logging level debug. 107 * 108 * @private 109 * @param {String} msg The logging message. 110 */ 111 debug: function(msg) { 112 console.debug(msg); 113 }, 114 115 /** 116 * This method is used to log a message on logging level error. 117 * 118 * @private 119 * @param {String} msg The logging message. 120 */ 121 error: function(msg) { 122 console.error(msg); 123 }, 124 125 /** 126 * This method is used to log a message on logging level warning. 127 * 128 * @private 129 * @param {String} msg The logging message. 130 */ 131 warn: function(msg) { 132 console.warn(msg); 133 }, 134 135 /** 136 * This method is used to log a message on logging level info. 137 * 138 * @private 139 * @param {String} msg The logging message. 140 */ 141 info: function(msg) { 142 console.info(msg); 143 } 144 145 });