2016-05-12 5 views
1

Ich benutze Winston, um eine Sails App einzuloggen. Das ist meine Konfiguration:Winston File Transport Protokolle Escape-Zeichen

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 
     }) 
    ], 
}); 

Aber in der Ausgabedatei gibt es ungerade Zeichen.

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

das sind Farben von der Konsole. – Bonanza

+0

ja, aber ich möchte vermeiden, diese Zeichen auszugeben. –

Antwort

0

Aktuell im Segel brauchen Sie nicht customLogger verwenden Winston zu verwenden. Sie können sails-hook-winston installieren. Als Ihr config/log.js so aussehen:

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 
     } 
    }] 
}; 

können Sie einige transports mit unterschiedlichen Log-Level in der gleichen Zeit verwenden.