vevlins
V2EX  ›  Node.js

有可能在 node 中调用一个 function,但控制 function 的输出流(console.log)吗?

  •  
  •   vevlins · Mar 3, 2020 · 3819 views
    This topic created in 2323 days ago, the information mentioned may be changed or developed.

    我要调用另外一个包,这个包有个函数内部有 console.log 。

    只知道调系统命令时可以控制 stdout,node 中有办法做到吗?

    3 replies    2020-03-11 21:08:03 +08:00
    Buges
        1
    Buges  
       Mar 3, 2020 via Android
    直接 override console.log 函数不行吗?
    zivyou
        2
    zivyou  
       Mar 3, 2020
    1l 标准答案
    himself65
        3
    himself65  
       Mar 11, 2020
    ```js
    const fn = console.log
    console.log = () => {}
    require('xxx.js')
    console.log = fn
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2488 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 16:04 · PVG 00:04 · LAX 09:04 · JFK 12:04
    ♥ Do have faith in what you're doing.