使用群集时Winston日志记录无法正常工作

时间:2015-08-18 22:09:56

标签: node.js winston

我目前正在启动群集应用,并且日志记录似乎无法输出。我正在为winston使用外部引用,以便我可以在我创建的任何节点中应用类似的日志,但即使是基本的控制台传输也无法正常工作。如果我用系统替换winston呼叫" console.log"调用,输出工作正常。不确定我在哪里出错:

logger.js

Cannot index into a null array.
At C:\tools\scripts\get-OU5.ps1:35 char:5
+     $dn = $result.Properties["distinguishedName"]
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

cluster.js

var winston = require('winston'),
    logger,
    customLevels = {workr: 0, info: 1, debug: 2, error: 3};
winston.emitErrs = true;
logger = new winston.Logger({levels: customLevels, exitOnError: false});
logger.enableConsole = function () {
    logger.add (winston.transports.Console, {
        name: 'console',
        formatter: function (options) {
            return options.level.toUpperCase() + ' - ' + options.message;
        }
    });
};
//I am omitting a file transport here
module.exports = logger;
module.exports.stream = {
    write: function(message, encoding){
        logger.info(message);
    }
};

1 个答案:

答案 0 :(得分:0)

这对我的Winston实现来说是一个问题。我没有在Winston中指定日志级别,这意味着它默认为' info'这比我的工作人员更高一级。水平。通过添加特定级别,它现在似乎正在起作用。

...
logger.enableConsole = function () {
    logger.add (winston.transports.Console, {
        name: 'console',
        formatter: function (options) {
            return options.level.toUpperCase() + ' - ' + options.message;
        },
        level: 'workr' // This was what I was missing
    });
};