forked from ibm-js/dworklight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.js
66 lines (59 loc) · 1.69 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
define([
"module",
"dojo/_base/array",
"dojo/_base/json",
"dojo/_base/lang",
"dojo/aspect",
"dojo/has",
"./sniff"
], function(module, array, json, lang, aspect, has) {
var MODULE = module.id;
var hc = {
_init : false
};
// Set up list style console output. Hybrids only output first argument :(
if ( !hc._init ) {
hc._init = true;
if ( has("worklight-hybrid") ) {
var _logProcess = function() {
var out = [];
array.forEach(arguments, function(item) {
if ( lang.isString(item) || !isNaN(item) ) {
out.push(item);
} else if ( item === null ) {
out.push("<null>");
} else if ( typeof(item) === "undefined" ) {
out.push("<undefined>");
} else {
try {
out.push( json.toJson(item) );
} catch(e) {
out.push( item );
}
}
});
return [out.join(" ")];
};
aspect.before(console , "debug" , _logProcess);
aspect.before(console , "log" , _logProcess);
aspect.before(console , "info" , _logProcess);
aspect.before(console , "warn" , _logProcess);
aspect.before(console , "error" , _logProcess);
if ( has("worklight") ) {
// Fix brain dead WL logger to support multiple args
aspect.before(WL.Logger , "debug" , _logProcess);
aspect.before(WL.Logger , "error" , _logProcess);
}
if ( has("worklight-android") ) {
// Redefine console to Worklight's Logger (for cleaner LogCat output)
console.debug = WL.Logger.debug;
console.log = WL.Logger.debug;
console.info = WL.Logger.debug;
console.warn = WL.Logger.error;
console.error = WL.Logger.error;
}
console.log("Hybrid Console - Env setup complete");
}
}
return hc;
});