Browse Source

gui logger wip

all-modes
Petr Balashov 8 years ago
parent
commit
c30855c8e3
  1. 8
      main.js
  2. 45
      routes/shepherd.js

8
main.js

@ -7,6 +7,7 @@ const electron = require('electron'),
path = require('path'),
url = require('url'),
os = require('os'),
md5 = require('md5'),
spawn = require('child_process').spawn,
exec = require('child_process').exec,
{ Menu } = require('electron'),
@ -28,7 +29,7 @@ Promise = require('bluebird');
const appBasicInfo = {
name: 'Agama',
version: '0.1.6.2e-beta'
version: '0.1.7.77a-beta'
};
app.setName(appBasicInfo.name);
@ -45,7 +46,9 @@ var shepherd = require('./routes/shepherd'),
shepherd.createIguanaDirs();
shepherd.writeLog('app init');
const appSessionHash = md5(new Date(Date.now()).toLocaleString);
shepherd.writeLog('app init ' + appSessionHash);
shepherd.writeLog('app info: ' + appBasicInfo.name + ' ' + appBasicInfo.version);
shepherd.writeLog('sys info:');
shepherd.writeLog('totalmem_readable: ' + formatBytes(os.totalmem()));
@ -170,6 +173,7 @@ io.on('connection', function(client) {
shepherd.setIO(io); // pass sockets object to shepherd router
shepherd.setVar('appBasicInfo', appBasicInfo);
shepherd.setVar('appSessionHash', appSessionHash);
module.exports = guiapp;
// END GUI App Settings

45
routes/shepherd.js

@ -27,7 +27,8 @@ var ps = require('ps-node'),
shepherd = express.Router(),
iguanaInstanceRegistry = {},
syncOnlyIguanaInstanceInfo = {},
syncOnlyInstanceInterval = -1;
syncOnlyInstanceInterval = -1,
guiLog = {};
// IGUANA FILES AND CONFIG SETTINGS
var iguanaConfsDirSrc = path.join(__dirname, '../assets/deps/confs'),
@ -100,7 +101,7 @@ shepherd.appConfig = {
shepherd.writeLog = function(data) {
const logLocation = iguanaDir + '/shepherd';
const timeFormatted = new Date(Date.now()).toLocaleString().replace('AM', '').replace('PM', '');
const timeFormatted = new Date(Date.now()).toLocaleString('en-US', { hour12: false });
if (fs.existsSync(logLocation + '/agamalog.txt')) {
fs.appendFile(logLocation + '/agamalog.txt', timeFormatted + ' ' + data + '\r\n', function (err) {
@ -168,6 +169,44 @@ shepherd.get('/coinslist', function(req, res, next) {
}
});
/*
* type: POST
* params: payload
*/
shepherd.post('/guilog', function(req, res, next) {
const logLocation = iguanaDir + '/shepherd';
if (!guiLog[shepherd.appSessionHash]) {
guiLog[shepherd.appSessionHash] = {};
}
if (guiLog[shepherd.appSessionHash][req.body.timestamp]) {
guiLog[shepherd.appSessionHash][req.body.timestamp].status = req.body.status;
guiLog[shepherd.appSessionHash][req.body.timestamp].response = req.body.response;
} else {
guiLog[shepherd.appSessionHash][req.body.timestamp] = {
'function': req.body.function,
'type': req.body.type,
'url': req.body.url,
'payload': req.body.payload,
'status': req.body.status,
};
}
fs.writeFile(logLocation + '/agamalog.json', JSON.stringify(guiLog), function (err) {
if (err) {
shepherd.writeLog('error writing gui log file');
}
const returnObj = {
'msg': 'success',
'result': 'gui log entry is added'
};
res.end(JSON.stringify(returnObj));
});
});
shepherd.post('/coinslist', function(req, res, next) {
const _payload = req.body.payload;
@ -206,6 +245,7 @@ shepherd.quitKomodod = function(chain) {
exec(komodocliBin + (chain ? ' ac_name=' + chain : '') + ' stop', function(error, stdout, stderr) {
console.log('stdout: ' + stdout)
console.log('stderr: ' + stderr)
if (error !== null) {
console.log('exec error: ' + error)
}
@ -1587,6 +1627,7 @@ shepherd.appInfo = function() {
sysInfo,
releaseInfo,
dirs,
appSession: shepherd.appSessionHash
};
}

Loading…
Cancel
Save