From 579bd3667e9209afabc188950e48cc7118296472 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Tue, 28 Feb 2017 16:28:29 +0100 Subject: [PATCH] refactored debug.log reader func --- package.json | 2 +- routes/shepherd.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 744cc7f..f6cc812 100644 --- a/package.json +++ b/package.json @@ -29,11 +29,11 @@ "express": "^4.14.0", "fix-path": "^2.1.0", "fs-extra": "^1.0.0", + "graceful-fs": "^4.1.11", "md5": "^2.2.1", "mkdirp": "^0.5.1", "pm2": "^2.3.0", "ps-node": "^0.1.4", - "read-last-lines": "^1.1.0", "socket.io": "^1.7.3" } } diff --git a/routes/shepherd.js b/routes/shepherd.js index 08fe046..a86b618 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -12,7 +12,6 @@ const electron = require('electron'), exec = require('child_process').exec, md5 = require('md5'), pm2 = require('pm2'), - readLastLines = require('read-last-lines'), request = require('request'), async = require('async'); @@ -783,9 +782,14 @@ shepherd.readDebugLog = function(fileLocation, lastNLines) { reject('readDebugLog error: ' + err); } else { console.log('reading ' + fileLocation); - readLastLines - .read(fileLocation, lastNLines) - .then((lines) => resolve(lines)); + _fs.readFile(fileLocation, 'utf-8', function(err, data) { + if (err) throw err; + + // TODO: truncate komodod debug.log on app start + var lines = data.trim().split('\n'); + var lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n'); + resolve(lastLine); + }); } }); } else {