I'd like my custom nodes to log in the seamlessly in terminal window or in the debug window. I was wondering if there are any best practices for this or a util that's available that will handle the timestamping and formatting.
I'm trying to avoid doint this:
this.socket.on('error', function (err) {
console.log(err.toString());
});
you can use node.log("words") to write to the log file, node.warn("words") to the log and sidebar, and node.error("words",msg) to create a error that the catch node can handle (and goes to the log) - and where msg is the incoming message that caused the error.
In those examples, this is your node. To access them inside a callback function like in your example, you'll want to assign this to a variable so you can reference it.
Additional note: while console.log takes multiple arguments and prints them space-separated, the various this.log, this.warn, this.error don't: they only have a single string argument (plus the msg argument for error).
There is still a role for console.log, which is to print a data structure. JSON.stringify can work as an alternative in many cases, but it barfs if there is any circularity. There's probably some helper in Node.js, though...