Profiling mongoose methods

I want to see logs of calling methods for all my mongoose methods, like this:

# Load Book
LoadBook = (id, cb) ->
  console.log 'loading book...'
  Book.findById id, (err, book) ->
    if err
      console.log err
      throw err
    console.log 'loaded book: ' + book.title
    cb book

I guess I can define post and pre methods like this:

BookSchema.pre 'save', (next) ->
  console.log 'loading ' + `model_name(don't know how to get it)` + ' ...'
  next()

And the same for other methods like findById or remove but it's long. And the error handling works only if I don't use callbacks, but I use it every time. I mean:

Part.on 'error', (err) ->
  console.log "Got an error", err

I think it doesn't work when there is a callback, does it? Perhaps there is some universal profiler in nodejs? I'm using express by the way.

You can use look module to profile your node.js app. It based on nodetime but works on local server.

You can enable debug logging in Mongoose by calling:

mongoose.set('debug', true);

With that enabled you'll get a log entry for every MongoDB operation made via Mongoose. Not sure if it's exactly what you want, but it's worth giving it a try.