通过 winston 管道 debug.js 输出

Piping debug.js output through winston

在我的公司,我们使用 Winston 处理我们自己的日志已经有一段时间了,但是处理其他使用 debugjs 的库的日志变得很麻烦,例如 Knex.js。 我们在考虑是否有办法通过 winston 传输 knex 的调试输出,但没有想出任何办法。

通过 winston 记录器传输所有内容的最佳方法是什么?

干杯!

取决于你想记录什么。

您可以连接 knex.on('query', ...)knex.on('query-response', ...)knex.on('query-error', ...) 以打印输出已发送的查询:

http://knexjs.org/#Interfaces-Events 在此答案

中也可以找到更多相关信息

我们正在使用这种解决方案来跟踪缓慢的查询和事务。

如果你想把所有内部 console.logs 移动到温斯顿,猴子修补 knex 助手 https://github.com/tgriesser/knex/blob/master/src/helpers.js 或 global console.log 几乎是唯一的选择。