2016-05-12 6 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

現在、セイルには、Winstonを使用するためにcustomLoggerを使用する必要はありません。 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を使用することができます。

関連する問題