2016-05-12 41 views
1

我正在使用winston登录Sails应用程序。这是我的配置:Winston文件传输日志转义字符

var customLogger = new winston.Logger({ 
    transports: [ 
     new(winston.transports.File)({ 
      level: 'debug', 
      filename: 'app.log', 
      colorize: false, 
      showLevel: false, 
      prettyPrint: false, 
      exitOnError: false, 
      json: true, 
      zippedArchive: true, 
      maxsize: 1000000000, 
      maxFiles: 30, 
      tailable: true 
     }), 
     new(winston.transports.Console)({ 
      level: 'info', 
      exitOnError: false, 
      colorize: false, 
      showLevel: false 
     }) 
    ], 
}); 

但是在输出文件中有奇怪的字符。

{"level":"info","message":"\u001b[32minfo: \u001b[39m","timestamp":"2016-05-12T17:58:03.281Z"} 
+0

这些是控制台的颜色。 – Bonanza

+0

是的,但我不想避免输出这些字符。 –

回答

0

当前处于启动状态,您无需使用customLogger即可使用Winston。您可以安装sails-hook-winston。比你config/log.js看起来就像是:

var path = require('path'); 
var pkgJSON = require(path.resolve('package.json')); 

module.exports.log = { 

    // This options are for Console transport that is used by default 
    level: 'info', // you are familiar with this value, right? 
    timestamp: true, // if you want to output the timestamp in the console transport 
    colors: false, 
    // Transports 
    // more information: https://github.com/winstonjs/winston/blob/master/docs/transports.md 
    transports: [{ 
     module: require('winston-daily-rotate-file'), 
     config: { 
      dirname: path.resolve('logs'), 
      datePattern: '.yyyy-MM-dd.log', 
      filename: pkgJSON.name, 
      prettyPrint: true, 
      timestamp: true, 
      level: 'info', 
      json: true, 
      colors: false 
     } 
    }] 
}; 

您可以在同一时间用不同的日志级别很少使用transports

相关问题