2016-05-12 7 views
1

Я использую winston для входа в приложение Sails. Это моя конфигурация:Winston File log log escape-символы

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 в то же время с разным уровнем лог.