3

我想在使用 mongoose 的数据访问层中记录错误。

如何使单元测试变得容易?将猫鼬(数据访问+中间件)与温斯顿(记录器)集成的最佳方法是什么。

谢谢,

帕维尔

4

1 回答 1

2

这是我如何mongoosewinston.

// Create the mongoose instance
var mongoose = require('mongoose');
mongoose.connect(...); // etc.

// Create the winston logger
var winston = require('winston')
  , logger = new (winston.Logger)({
      transports: new (winston.transports.Console)({
        uncaughtException: true,
        level: 'debug',
        colorize: 'true'
      }),
    });

// Configure mongoose for debug
mongoose.set('debug', function (collectionName, method, query, doc, options) {
  logger.info('mongo collection: %s method: %s', collectionName, method);
});
于 2013-08-01T02:44:02.643 回答