forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.js
More file actions
35 lines (30 loc) · 1.03 KB
/
browser.js
File metadata and controls
35 lines (30 loc) · 1.03 KB
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
'use strict';
var enabled = require('enabled');
/**
* Bare minimum browser version of diagnostics. It doesn't need fancy pancy
* detection algorithms. The code is only enabled when *you* enable it for
* debugging purposes.
*
* @param {String} name Namespace of the diagnostics instance.
* @returns {Function} The logger.
* @api public
*/
module.exports = function factory(name) {
if (!enabled(name)) return function diagnopes() {};
return function diagnostics() {
var args = Array.prototype.slice.call(arguments, 0);
//
// We cannot push a value as first argument of the argument array as
// console's formatting %s, %d only works on the first argument it receives.
// So in order to prepend our namespace we need to override and prefix the
// first argument.
//
args[0] = name +': '+ args[0];
//
// So yea. IE8 doesn't have an apply so we need a work around to puke the
// arguments in place.
//
try { Function.prototype.apply.call(console.log, console, args); }
catch (e) {}
};
};