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