Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format Mongoose debug output - pretty print

How can I make Mongoose debug output look pretty in console? Currently the output is displayed on one line.

like image 610
finspin Avatar asked Mar 22 '23 18:03

finspin


1 Answers

Here is something I put together, maybe somebody will find it useful.

Install colors module for node.js (this is optional): npm install colors

Then in your file:

var colors = require('colors');

mongoose.set('debug', function (collectionName, method, query, doc) {
  console.log(
    'Mongoose: '.cyan + 
    collectionName + 
    '.' + 
    method + 
    ' (' + 
    JSON.stringify(query, null, 2) + ')');
});
like image 101
finspin Avatar answered Mar 24 '23 10:03

finspin