mongoose调试日志到单独的文件

Dam*_*ran 3 debugging mongoose node.js express

我将mongoose调试设置为true.

mongoose.set('debug',true)

但是现在调试日志是在console中打印的.我需要为mongoose debug指定一个单独的文件,以便我可以在需要时检查查询.我该怎么做?

小智 11

伟大的aaron heckmann在Logging outbound查询中回答了这个问题

mongoose.set('debug', function (collectionName, method, query, doc [, options]) {

  //save to file what you need

});
Run Code Online (Sandbox Code Playgroud)