This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
console.js
51 lines (48 loc) · 1.55 KB
/
console.js
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
/**
* Console log handler. Outputs logs to console.
*
* @memberof Canadarm.Handler
* @function consoleLogHandler
*
* @example
* Canadarm.addHandler(Canadarm.Handler.consoleLogHandler);
*
* // In Chrome the output looks similar to:
* [ERROR]: two is not defined
* characterSet: "windows-1252"
* columnNumber: "17"
* language: "en-US"
* lineNumber: "17"
* logDate: "2015-04-22T21:35:40.389Z"
* msg: "[ERROR]: two is not defined"
* pageURL: "http://localhost:8000/html/"
* scriptURL: "http://localhost:8000/js/broken.js"
* stack: "ReferenceError: two is not defined↵
* at broken_watched_function (http://localhost:8000/js/broken.js:17:17)↵
* at wrapper (http://localhost:8000/js/canadarm.js:616:17)↵
* at http://localhost:8000/js/broken.js:60:40
* "type: "jserror"
*
* @param {object} logAttributes - the attributes to log, key/value pairs, no nesting.
*/
function consoleLogHandler(logAttributes) {
var logValues = '', key;
if (console) {
// detect IE
if (window.attachEvent) {
// Put attributes into a format that are easy for IE 8 to read.
for (key in logAttributes) {
if (!logAttributes.hasOwnProperty(key)) {
continue;
}
logValues += key + '=' + logAttributes[key] + '\n';
}
console.error(logValues);
} else if (typeof logAttributes.msg !== 'undefined') {
console.error(logAttributes.msg, logAttributes);
} else {
console.error(logAttributes);
}
}
}
Canadarm.Handler.consoleLogHandler = consoleLogHandler;