0

I'm trying to understand how to use Winston (NodeJS) by creating a logger with custom levels.

logger.js

  var winston = require('winston');

  var custom = {
    levels: {
      debug: 0,
      log  : 1,
      info : 2,
      ok   : 3,
      warn : 4,
      cry  : 5,
      fail : 6
    },
    colors: {
      debug: 'grey',
      log  : 'white',
      info : 'cyan',
      ok   : 'green',
      yay  : 'blue',
      warn : 'yellow',
      cry  : 'magenta',
      fail : 'red'
    }
  };

  var customLogger = new (winston.Logger)({
      transports: [
          new (winston.transports.Console)({ colorize:true, prettyPrint: true, level: 'fail', timestamp:false })
      ],
      levels:custom.levels, colors:custom.colors
  });

module.exports = customLogger;

//in includes.js

var logger = require('./lib/logger.js');
exports.logger = logger;

//in app.js

var logger = require('includes').logger
logger.cry("Wah Wah Wah");

But everytime I try to include my custom logger and use it I get:

 RangeError: Maximum call stack size exceeded

What am I doing wrong here?

4

1 回答 1

2

The one thing that immediately comes to mind is to include logger.js directly in app.js rather than going through includes.js.

I'd love to help more, but with the files in those locations and nothing else to go on but what you've said, as far as I can tell your app shouldn't work at all.

于 2012-11-08T23:14:27.727 回答