This repository has been archived by the owner on Aug 12, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (62 loc) · 1.87 KB
/
index.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
67
68
69
70
71
72
"use strict";
var argv = require("optimist").argv;
var inspect = require("eyes").inspector();
exports.setup = function(config){
config = config || {};
if("inspectOpts" in config){
inspect = require("eyes").inspector(config.inspectOpts);
}else if(argv["legendary-inspect-opts"]){
inspect = require("eyes").inspector(JSON.parse(argv["legendary-inspect-opts"]));
}
if("tracer" in config){
if(config.tracer === true){
exports.logTraces();
}
}else if(argv["legendary-tracer"]){
exports.logTraces();
}
if("unhandled" in config){
if(config.unhandled === true || typeof config.unhandled === "number"){
exports.logUnhandled(config.unhandled === true ? 1000 : config.unhandled);
}
}else if("legendary-unhandled" in argv){
exports.logUnhandled(typeof argv["legendary-unhandled"] === "number" ? argv["legendary-unhandled"] : 1000);
}
};
exports.enableTracer = function(){
return require("./lib/tracer");
};
exports.logTraces = function(){
var tracer = exports.enableTracer();
["fulfilled", "rejected"].forEach(function(type){
tracer.on(type, function(value, label, meta){
if(label){
label += " (" + type + ")";
}else{
label = type;
}
inspect(value, label);
if(typeof meta !== "undefined"){
inspect(meta, label + " (meta)");
}
});
});
};
exports.catchUnhandled = function(){
return require("./lib/unhandled");
};
exports.logUnhandled = function(delay){
if(!delay){
exports.catchUnhandled().on("unhandled", function(tracked){
inspect(tracked.reason, "unhandled rejection");
});
}else{
exports.catchUnhandled().on("unhandled", function(tracked){
setTimeout(function(){
if(!tracked.handled){
inspect(tracked.reason, "unhandled rejection @ " + new Date(tracked.timestamp).toISOString());
}
}, delay);
});
}
};