How to safely wrap `console.log`?

后端 未结 10 497
日久生厌
日久生厌 2021-01-31 14:13

Suppose I want to include some calls to console.log for some legitimate production reason, say for something like a unit test harness. Obviously I would not want th

10条回答
  •  清酒与你
    2021-01-31 15:08

    Use Consolation

    My ridiculously overengineered console:

    • prevents errors if there's no console
    • prevents logging in production if you left console.log statements in your code
    • supports console.error, console.group, and all such other methods
    • still gives you backtraces to your log statements

    It's amazing.

    But really, you just shouldn't leave console statements lying around in your code.

    Behold and tremble! Presenting: Consolation.js

提交回复
热议问题