【问题标题】:override Nodejs console to add the line the function were called覆盖 Nodejs 控制台以添加调用函数的行
【发布时间】:2018-08-21 09:06:37
【问题描述】:

有没有办法发送已调用控制台函数的行和文件?

我有一个包含许多控制台日志和控制台错误的应用程序。这对我来说是件好事,问题是我需要知道他们来自哪里。

我尝试覆盖 console.error 并在里面添加 console.trace 但这只是创建了对控制台错误的递归调用(我猜它们都是由进程 strerr 触发的)

这是我尝试过的

const tempConsoleError = console.error.bind(console);
console.error = function (err) {
    console.log('i am in error')
  
    tempConsoleError(err);
    
    console.trace()
};
console.error('error string ')

【问题讨论】:

标签: javascript node.js console


【解决方案1】:

最后写了一个包来做这件事。是使用“堆栈跟踪”和节点全局

console-from

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 2016-07-30
    • 2010-10-25
    • 2014-07-13
    • 2020-12-15
    相关资源
    最近更新 更多