Node.js console.log performance

Viewed 18186

If your Node.js code is littered with console.log statements are you inviting performance issues? Is it worth debug/production toggling this on/off? I realized logging is important to prod in general - but I'm generally curious if the console output has a performance hit?

In Chrome it definitely seems to degrade performance if the console is open.

4 Answers

As said above, the console.log is asynchronous and non-blocking, so it would not slow your application too much except one tick for the function invocation.

But it is a good habit to use some module to turn some logs of certain level off when deploy it in production instead of using console.log directly. There have been several good ones as @Alfred listed.

The Nodejs official blog posted an article suggesting use JSON format for logging, check it out at Service logging in JSON with Bunyan, and Bunyan for nodejs is really worth trying.

Related