根据他们的文档(http://deepstream.io/docs/deepstream.html),它说我可以将默认记录器更改为我自己的记录器:

server.set( 'Logger', new FileLogger() );

(顺便说一句, Logger 应该是 logger 。使用Logger时会抛出Error: Unknown option "Logger")。但是,我想使用Bunyan作为默认记录器,并且尝试了以下变体:
var logger = bunyan.createLogger({
  name: "backend",
  streams: streams,
  serializers: {
    row: function (row) {
        if (row) {
            return row;
        }
        return null;
    },
    filename: function (filename) {
        if (filename) {
            return require("path").basename(filename);
        }
        return null;
    }
  }
});

server.set('logger', new logger.info());
server.set('logger', logger.info.bind(console));
server.set('logger', logger.info.bind(logger));
server.set('logger', logger);
server.set('logger', logger.info);

我不断收到的错误是:
TypeError: this._options.logger.log is not a function
  at DependencyInitialiser._onReady (node_modules/deepstream.io/src/utils/dependency-initialiser.js:53:23)
  at new DependencyInitialiser (node_modules/deepstream.io/src/utils/dependency-initialiser.js:25:8)
  at Deepstream.start (node_modules/deepstream.io/src/deepstream.io.js:121:17)
  at Server.<anonymous> (bin/run.js:139:18)
  at Server.g (events.js:260:16)
  at emitNone (events.js:72:20)
  at Server.emit (events.js:166:7)
  at emitListeningNT (net.js:1260:10)
  at doNTCallback1 (node.js:428:9)
  at process._tickDomainCallback (node.js:391:17)

最佳答案

Deepstream希望其记录器实现两种方法:

/**
 * Logs a line
 *
 * @param   {Number} logLevel   One of the C.LOG_LEVEL constants
 * @param   {String} event      One of the C.EVENT constants
 * @param   {String} logMessage Any string
 *
 * @public
 * @returns {void}
 */
Logger.prototype.log = function( logLevel, event, logMessage ) {};

/**
 * Sets the log-level. This can be called at runtime.
 *
 * @param   {Number} logLevel   One of the C.LOG_LEVEL constants
 *
 * @public
 * @returns {void}
 */
Logger.prototype.setLogLevel = function( logLevel ) {};

这样,为Bunyan编写适配器应该相当简单。另请参阅Deepstream的std-out-logger作为引用:

https://github.com/hoxton-one/deepstream.io/blob/master/src/default-plugins/std-out-logger.js

08-07 09:04