Sails.js日志系统

时间:2014-03-22 21:19:27

标签: logging sails.js

我需要实现对sails服务器的日志记录。 我找到了sails logging to file

但我恐怕不太了解它。 意图是用日志系统替换console.log。

这只是我需要实现记录器的许多地方的一个例子:

  s3.putObject(params, function (err, data) {
                        if (err)
                            console.log(err);
                        else                         
                            console.log("Successfully uploaded " + 

//等

3 个答案:

答案 0 :(得分:4)

如果您在sails.log.error()文件中进行配置,则可以使用sails.log.warn()sails.log.verbose()config/logs.js等将日志发送到控制台,甚至发送到文件。在那里,您还可以指定要在输出中获取的日志级别,或者您可以在sails命令行(--verbose)中传递参数。

答案 1 :(得分:1)

只需将其放入您的config / log.js

var winston = require('winston');
var customLogger = new winston.createLogger();

// A console transport logging debug and above.
customLogger.add(new winston.transports.Console, {
  level: 'debug',
  colorize: true
});

// A file based transport logging only errors formatted as json.
customLogger.add(new winston.transports.File({
  level: 'error',
  filename: './error.log',
  json: true,
  colorize: true
}));

module.exports.log = {
  // Pass in our custom logger, and pass all log levels through.
  custom: customLogger,
  level: 'silly',

  // Disable captain's log so it doesn't prefix or stringify our meta data.
  inspect: false
};

现在,每当您调用sails.log.error()时,它将在error.log文件中列出您的日志

sails.log.error("Error demo message");

答案 2 :(得分:1)

我使用过 sails.log("message")sails.log.debug("message or variable")sails.log.error("error message or variable")