readStream .pipe(split(JSON.parse)) .on('data', function (line) { line.id = ++n; console.log(`${n}: ${JSON.stringify(line)}`); });
// Log every request (not /) to the console app.use(morgan('dev', { skip: function(req, res) { if(req.url == "/") return true; }, stream: require('split')().on('data', function(line) { process.stdout.write(moment().format("YYYY-MM-DD HH:mm:ss-SSS") + " " + line + "\n"); }) }));
split().on('data', (message) => { logger.info(message); })
app.use(morgan('dev', { skip: function(req, res) { // Remove spamming useless logs var skipArray = ["/update_logs", "/get_pourcent_generation", "/status", "/completion", "/watch", "/"]; var currentURL = req.originalUrl; if (currentURL.indexOf("?") != -1) { // Remove params from URL currentURL = currentURL.split("?")[0]; } if (skipArray.indexOf("/"+currentURL.split("/")[currentURL.split("/").length -1]) != -1) { return true; } }, stream: split().on('data', function(line) { if (allLogStream.bytesWritten < 5000) { if(globalConf.env != "develop"){ allLogStream.write(moment().format("MM-DD HH:mm:ss") + ": " + ansiToHtml.toHtml(line) + "\n"); process.stdout.write(moment().format("MM-DD HH:mm:ss") + " " + line + "\n"); } else { allLogStream.write(ansiToHtml.toHtml(line) + "\n"); process.stdout.write(line + "\n"); } } else { /* Clear all.log if too much bytes are written */ fs.writeFileSync(path.join(__dirname, 'all.log'), ''); allLogStream.bytesWritten = 0; } }) }));
return new Promise((resolve, reject) => { const reader = fs.createReadStream(filename); reader.on('error', err => { reject(err); }); reader.on('open', () => { let shasum; if (shouldHash) { let error; const byLine = reader.pipe(split()); byLine.on('error', (e) => { error = e; }); byLine.on('data', (d) => { if (shouldHash) { shasum.update(d); byLine.on('end', () => { if (error) { reject(error);
// Log every request (not /) to the console app.use(morgan('dev', { skip: function(req, res) { if(req.url == "/") return true; }, stream: require('split')().on('data', function(line) { process.stdout.write(moment().format("YYYY-MM-DD HH:mm:ss-SSS") + " " + line + "\n"); }) }));
split().on('data', (message) => { logger.info(message); })