-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlog.js
43 lines (36 loc) · 1 KB
/
dlog.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
// DLog.js
Object.defineProperty(global, '__stack', {
get: function() {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack) {
return stack;
};
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
}
});
const log = (type, args) => {
const filePath = __stack[2].getFileName();
const fileName = filePath.substring(filePath.lastIndexOf('/') + 1);
const line = __stack[2].getLineNumber();
const r = new RegExp('T(.*)Z');
const time = (new Date()).toISOString().match(r)[1];
console.log('•', time, '[DLOG]', type, `<${fileName}:${line}>`, args.join(' '));
}
const info = (...args) => {
log('✅ [INFO]', args);
};
const debug = (...args) => {
log('▶️ [DEBUG]', args);
};
const error = (...args) => {
log('⚠️ [ERROR]', args);
};
module.exports = {
info,
debug,
error,
};