Node.js console.log performance

前端 未结 4 526
无人及你
无人及你 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:48

    Edit:

    console.log is synchronous and it is blocking the event loop


    I think this is low hanging fruit, and will almost not give you any speed bump at all when you disable logging(if not used rigorously in critical parts). Probably the console.log is implemented in pure C. Also there are some modules available which can turn off logging in production, just as you can do with socket.io:

    • https://github.com/nomiddlename/log4js-node
    • https://github.com/visionmedia/log.js

提交回复
热议问题