1
0
goodtimes/server/console-line.js
James Ketrenos c7435c4bb1 eslinted everything and moved db around
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
2022-04-07 14:25:20 -07:00

31 lines
861 B
JavaScript
Executable File

/* monkey-patch console.log to prefix with file/line-number */
if (process.env.LOG_LINE) {
let cwd = process.cwd(),
cwdRe = new RegExp('^[^/]*' + cwd.replace('/', '\\/') + '\/([^:]*:[0-9]*).*$');
[ 'log', 'warn', 'error' ].forEach(function(method) {
console[method] = (function () {
let orig = console[method];
return function () {
function getErrorObject() {
try {
throw Error('');
} catch (err) {
return err;
}
}
let err = getErrorObject(),
caller_line = err.stack.split('\n')[3],
args = [caller_line.replace(cwdRe, '$1 -')];
/* arguments.unshift() doesn't exist... */
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
orig.apply(this, args);
};
})();
});
}