namibia
c449ac80b48405f72fd700d5cd406397b3a17d8a
1 2 3 4 5 6 7 8 9 10 11 12 13 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
/** * Debugging class. */ ;(function(){ window.tantrum = function(context, task, message) { this.context = context; this.task = task; this.message = message; bug.error('EXCEPTION on ' + context, task, message); }; window.bug = { /** * Debug level. * 0 : No logging * 1 : Errors only * 2 : Errors and warnings * 3 : Errors, warnings and information * 4 : Errors, warnings, information and dumps * 5 : Flood mode, hope you can swim * @type {Number} */ _debugLevel : 3, /** * Set debug verbosity level. * @param {Number} level Debug verbosity level */ setLevel : function(level) { bug._debugLevel = level; }, /** * Start a logging group. * @param {String} groupName Name of the group */ group : function(groupName) { console.groupCollapsed(groupName); }, /** * End the current logging group. */ ungroup : function() { console.groupEnd(); }, /** * Log an error. * @param {String} context Module, class or object context * @param {String} task The task * @param {Unknown} data The data to log */ error : function(context, task, data) { if (0 < bug._debugLevel) { bug._handle('', 'error', context, task, data); } }, /** * Log a warning. * @param {String} context Module, class or object context * @param {String} task The task * @param {Unknown} data The data to log */ warn : function(context, task, data) { if (1 < bug._debugLevel) { bug._handle('', 'warn', context, task, data); } }, debug : function(context, task, data) { if (1 < bug._debugLevel) { bug._handle('-oO- ', 'warn', context, task, data); } }, /** * Log some information. * @param {String} context Module, class or object context * @param {String} task The task * @param {Unknown} data The data to log */ info : function(context, task, data) { if (2 < bug._debugLevel) { bug._handle('(i) ', 'log', context, task, data); } }, /** * Dump some information, probably lots of it. * @param {String} context Module, class or object context * @param {String} task The task * @param {Unknown} data The data to log */ dump : function(context, task, data) { if (3 < bug._debugLevel) { bug._handle('<dump> ', 'log', context, task, data); } }, /** * Drown the developer in tons of information. * @param {String} context Module, class or object context * @param {String} task The task * @param {Unknown} data The data to log */ drown : function(context, task, data) { if (4 < bug._debugLevel) { bug._handle('..... ', 'log', context, task, data); } }, /** * Internal utility to do the actual logging. * @param {String} level Logging level * @param {String} method Console method to use * @param {String} context Module, class or object context * @param {String} task The task * @param {Unknown} data The data to log */ _handle : function(level, method, context, task, data, wrap) { if (undefined == data && undefined == task) { console[method](level, context); } else if (undefined == data) { console[method](level + context, task); } else { console[method](level + context + ':' + task, data); } } }; })(); |
Commits for namibia/public/js/app/debug.js
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |