Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoose debug log to separate file

I set the mongoose debug to true.

mongoose.set('debug', true)

But now the debug log is printing in console.I need to specify a separate file for mongoose debug so that I can check the queries if needed.How can I do that?

like image 825
Damodaran Avatar asked Dec 04 '25 11:12

Damodaran


2 Answers

the great aaron heckmann answered this in Logging outbound queries

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

  //save to file what you need

});
like image 168
maxwellium Avatar answered Dec 06 '25 14:12

maxwellium


Well, you would probably have to open a filehandle and write the error to that file.

But for a short-cut, what I do is capture all output of console and log it to a file when I start my app:

node app.js 1>$APP_DIR/log/app.log 2>&1 &

Then you can tail the log file:

tail -f ./log/app.log
like image 33
chovy Avatar answered Dec 06 '25 14:12

chovy