Node.js console.log performance

前端 未结 4 539
无人及你
无人及你 2021-02-01 04:15

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 import

4条回答
  •  情话喂你
    2021-02-01 04:54

    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.

提交回复
热议问题