Javascript console.log Prefixes

Recently I was working on a project in Node.js that involved forking several processes. In order to make the console more readable (and easier for me to debug) I appended a unique tag to each individual processes’s console.log so that I knew which process was logging what. Here is how:

// adding a tag to all console logs!
var originalConsoleLog = console.log;
console.log = function() {
    args = [];
    args.push( '[' + process_name + '] ' );
    // Note: arguments is part of the prototype
    for( var i = 0; i < arguments.length; i++ ) {
        args.push( arguments[i] );
    }
    originalConsoleLog.apply( console, args );
};
Thats it! Without modifying any existing console.log statements we now have a prefix that will make it much easier to sift through those logs. Here is a sample log that might show you why this is useful!
[process a] Created user with id 12
[process c] Update existing user with id 4
[process b] Deleted comment with id 55
[process b] Deleted comment with id 45
...