Javascript - Override console.log and keep the old function

前端 未结 8 1299
春和景丽
春和景丽 2021-01-12 08:49

I would like to override console.log and call it on my new function.

I try something like this but I get Uncaught TypeError: Illegal invocation:

8条回答
  •  Happy的楠姐
    2021-01-12 09:22

    I would recommend using: https://github.com/sunnykgupta/jsLogger

    Features:

    1. It safely overrides the console.log.
    2. Takes care if the console is not available (oh yes, you need to factor that too.)
    3. Stores all logs (even if they are suppressed) for later retrieval.
    4. Handles major console functions like log, warn, error, info.

    Is open for modifications and will be updated whenever new suggestions come up.

    Disclaimer: I am the author of the plugin.

提交回复
热议问题