Skip to content

Instantly share code, notes, and snippets.

@dbuezas
Created February 17, 2017 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbuezas/0530a705fe017f8162b1aed76362a9af to your computer and use it in GitHub Desktop.
Save dbuezas/0530a705fe017f8162b1aed76362a9af to your computer and use it in GitHub Desktop.
// Just require this file
// david@shop.co
// npm install colors
var ms, oldLog, path,
slice = [].slice;
require('colors');
path = require('path');
oldLog = console.log;
ms = function() {
var decimal, hours, minutes, now, seconds;
now = new Date();
decimal = Math.floor(now.getMilliseconds() / 100);
seconds = Math.floor(now.getSeconds());
minutes = Math.floor(now.getMinutes());
hours = Math.floor(now.getHours());
hours = hours < 10 ? '0' + hours : hours;
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds = seconds < 10 ? '0' + seconds : seconds;
return hours + ':' + minutes + ':' + seconds + '.' + decimal;
};
console.log = function() {
var args, err, filename, functionName, line_col, line_num, trace, trace_line;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
try {
throw new Error();
} catch (error) {
err = error;
trace = err.stack.split("\n");
}
try {
trace.shift();
trace.shift();
trace_line = trace.shift();
while ((trace_line.indexOf('at SubtaskBot.logNode') > -1) || (trace_line.indexOf('at SubtaskBot.logPhantom') > -1)) {
trace_line = trace.shift();
}
trace = trace_line.match(/^ +at (.+) \((.+):(\d+):(\d+)\)/);
if (trace != null) {
functionName = trace[1];
filename = path.basename(trace[2]);
line_num = Number(trace[3]);
line_col = Number(trace[4]);
} else {
trace = trace_line.match(/^ +at (.+):(\d+):(\d+)/);
functionName = 'global';
filename = path.basename(trace[1]);
line_num = Number(trace[2]);
line_col = Number(trace[3]);
}
return process.stdout.write(((ms()) + "-" + filename + ":" + line_num + " > ").bgBlue);
} finally {
oldLog.apply(console, args);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment