From 0fd1117791f429fb951aacd7fb2a570394096cab Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Thu, 16 Feb 2017 15:05:14 +0100 Subject: [PATCH] read debug log (wip) --- package.json | 3 +- routes/shepherd.js | 95 ++++++++++++++++++++++++++-------------------- 2 files changed, 55 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index dc3a701..72f95dd 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "md5": "^2.2.1", "mkdirp": "^0.5.1", "pm2": "^2.3.0", - "ps-node": "^0.1.4" + "ps-node": "^0.1.4", + "read-last-lines": "^1.1.0" } } diff --git a/routes/shepherd.js b/routes/shepherd.js index 2bdccb0..a85b91a 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -10,7 +10,8 @@ const electron = require('electron'), express = require('express'), exec = require('child_process').exec, md5 = require('md5'), - pm2 = require('pm2'); + pm2 = require('pm2'), + readLastLines = require('read-last-lines'); Promise = require('bluebird'); @@ -79,51 +80,11 @@ shepherd.get('/', function(req, res, next) { }); shepherd.get('/appconf', function(req, res, next) { + shepherd.readDebugLog(); var obj = shepherd.loadLocalConfig(); res.send(obj); }); -shepherd.loadLocalConfig = function() { - if (fs.existsSync(iguanaDir + '/config.json')) { - var localAppConfig = fs.readFileSync(iguanaDir + '/config.json', 'utf8'); - console.log('app config set from local file'); - - // find diff between local and hardcoded configs - // append diff to local config - var compareJSON = function(obj1, obj2) { - var result = {}; - - for (var i in obj1) { - if (!obj2.hasOwnProperty(i)) { - result[i] = obj1[i]; - } - } - - return result; - }; - - var compareConfigs = compareJSON(shepherd.appConfig, JSON.parse(localAppConfig)); - if (Object.keys(compareConfigs).length) { - var newConfig = Object.assign(JSON.parse(localAppConfig), compareConfigs); - - console.log('config diff is found, updating local config'); - console.log('config diff:'); - console.log(compareConfigs); - - shepherd.saveLocalAppConf(newConfig); - return newConfig; - } else { - return JSON.parse(localAppConfig); - } - - } else { - console.log('local config file is not found!'); - shepherd.saveLocalAppConf(shepherd.appConfig); - - return shepherd.appConfig; - } -}; - shepherd.post('/herd', function(req, res) { console.log('======= req.body ======='); //console.log(req); @@ -191,6 +152,56 @@ shepherd.post('/getconf', function(req, res) { res.end('{ "msg": "success", "result": "' + confpath + '" }'); }); +shepherd.loadLocalConfig = function() { + if (fs.existsSync(iguanaDir + '/config.json')) { + var localAppConfig = fs.readFileSync(iguanaDir + '/config.json', 'utf8'); + console.log('app config set from local file'); + + // find diff between local and hardcoded configs + // append diff to local config + var compareJSON = function(obj1, obj2) { + var result = {}; + + for (var i in obj1) { + if (!obj2.hasOwnProperty(i)) { + result[i] = obj1[i]; + } + } + + return result; + }; + + var compareConfigs = compareJSON(shepherd.appConfig, JSON.parse(localAppConfig)); + if (Object.keys(compareConfigs).length) { + var newConfig = Object.assign(JSON.parse(localAppConfig), compareConfigs); + + console.log('config diff is found, updating local config'); + console.log('config diff:'); + console.log(compareConfigs); + + shepherd.saveLocalAppConf(newConfig); + return newConfig; + } else { + return JSON.parse(localAppConfig); + } + + } else { + console.log('local config file is not found!'); + shepherd.saveLocalAppConf(shepherd.appConfig); + + return shepherd.appConfig; + } +}; + +shepherd.readDebugLog = function() { + console.log('reading debug.log'); + console.log(komodoDir + '/debug.log'); + + readLastLines + .read(komodoDir + '/debug.log', 50) + .then((lines) => console.log(lines)); +}; + function herder(flock, data) { //console.log(flock); //console.log(data);