2017-01-19 4 views
0

J'essaie d'obtenir un fichier journal réécrit de moins de 20mb. J'ai configuré mon appendeur de fichier log4js avec le paramètre maxlogsize comme 20mb, mais cela ne fonctionne pas. Enregistreur écrire des fichiers journaux supérieurs à 20 Mo. Alors peut-être quelqu'un sait comment résoudre ce problème?nœud log4js maxlogsize ne fonctionne pas

"use strict"; 

let path = require("path"); 
let log4js = require('log4js'); 

let $depth = 10; 
log4js.configure({ 
    appenders: [ 
     { 
      type: "console", 
      layout: { 
       type : "pattern", 
       pattern : "[%d{ISO8601}] %[%p {%x{ln}} -%]\t%m", 
       tokens: { 
        ln : function() { 
         var errorStack = (new Error).stack.split("\n"); 
         var tempLocation = errorStack[$depth]; 
         if (typeof tempLocation !== 'undefined' && tempLocation) { 
          return tempLocation .replace(/^\s+at\s+(\S+)\s\((.+?)([^\/]+):(\d+):\d+\)$/, function(){ 
           return arguments[1] +' '+ arguments[3] +' line '+ arguments[4]; 
          }); 
         } 
        } 
       } 
      } 
     }, 
     { 
      type: "file", 
      filename: __dirname + '/../data/' + "/smartHomeServer.log", 
      layout: { 
       type : "pattern", 
       pattern : "[%d{ISO8601}] %[%p {%x{ln}} -%]\t%m", 
       maxLogSize: 20971520, 
       backups: 1, 
       tokens: { 
        ln : function() { 
         var errorStack = (new Error).stack.split("\n"); 
         var tempLocation = errorStack[$depth]; 
         if (typeof tempLocation !== 'undefined' && tempLocation) { 
          return tempLocation.replace(/^\s+at\s+(\S+)\s\((.+?)([^\/]+):(\d+):\d+\)$/, function() { 
           return arguments[1] + ' ' + arguments[3] + ' line ' + arguments[4]; 
          }); 
         } 
        } 
       } 
      } 
     } 
    ] 
}); 
let log = log4js.getLogger(); 

module.exports = log; 
+0

FIXE: J'ai fait une erreur dans appender. maxLogSize et les sauvegardes doivent être au niveau supérieur. –

Répondre

0

appender fixe:

{ 
     type: "file", 
     filename: __dirname + '/../data/' + "/smartHomeServer.log", 
     maxLogSize: 20971520, 
     backups: 1, 
     layout: { 
      type : "pattern", 
      pattern : "[%d{ISO8601}] %[%p {%x{ln}} -%]\t%m", 
      tokens: { 
       ln : function() { 
        var errorStack = (new Error).stack.split("\n"); 
        var tempLocation = errorStack[$depth]; 
        if (typeof tempLocation !== 'undefined' && tempLocation) { 
         return tempLocation.replace(/^\s+at\s+(\S+)\s\((.+?)([^\/]+):(\d+):\d+\)$/, function() { 
          return arguments[1] + ' ' + arguments[3] + ' line ' + arguments[4]; 
         }); 
        } 
       } 
      } 
     } 
    }