I have the following code:
var myLog = console.log.bind(console, '[DEBUG]');
Which works find when I want to log things prepended with [DEBUG]
to the console.
Now I want to add a date/time to the log and I tried this:
var myLog = console.log.bind(console, '[DEBUG ' + (new Date) + ']');
Which obviously does not work because it always logs the same time (the time that the .bind
was called).
Is there any way (using .bind
) to log the current time on each log without having to do this:
var myLog = function(){
var args = ['[DEBUG ' + (new Date) + ']'];
for(var i = 0; i < arguments.length; ++i) {
args.push(arguments[i]);
}
return console.log.apply(console, args);
};
?
Because the above method shows me the line that console.log.apply
was called and not the line that myLog
was called.