Browse Source

add logging for UI gekkos, fix #972

develop
Mike van Rossum 4 years ago
parent
commit
315f97e1fa
5 changed files with 57 additions and 5 deletions
  1. +1
    -3
      core/workers/pipeline/messageHandlers/realtimeHandler.js
  2. +2
    -0
      logs/.gitignore
  3. +2
    -2
      web/routes/baseConfig.js
  4. +12
    -0
      web/routes/startGekko.js
  5. +40
    -0
      web/state/logger.js

+ 1
- 3
core/workers/pipeline/messageHandlers/realtimeHandler.js View File

@ -5,14 +5,12 @@ module.exports = cb => {
return {
message: message => {
if(message.type === 'error') {
cb(message.error);
console.error(message.error);
}
else if(message.type === 'log')
console.log(message.log);
else
cb(null, message);

+ 2
- 0
logs/.gitignore View File

@ -0,0 +1,2 @@
*
!.gitignore

+ 2
- 2
web/routes/baseConfig.js View File

@ -6,8 +6,8 @@ var config = {};
// GENERAL SETTINGS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
config.silent = true;
config.debug = false;
config.silent = false;
config.debug = true;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CONFIGURING TRADING ADVICE

+ 12
- 0
web/routes/startGekko.js View File

@ -4,6 +4,7 @@ const moment = require('moment');
const pipelineRunner = promisify(require('../../core/workers/pipeline/parent'));
const cache = require('../state/cache');
const Logger = require('../state/logger');
const broadcast = cache.get('broadcast');
const apiKeyManager= cache.get('apiKeyManager');
const gekkoManager = cache.get('gekkos');
@ -49,6 +50,15 @@ module.exports = function *() {
let errored = false;
var logType = type;
if(logType === 'leech') {
if(config.trader && config.trader.enabled)
logType = 'tradebot';
else
logType = 'papertrader';
}
const logger = new Logger(logType);
console.log('Gekko', id, 'started');
const child = pipelineRunner(mode, config, (err, event) => {
@ -102,6 +112,8 @@ module.exports = function *() {
}
broadcast(wsEvent);
return;
} else if(event.log) {
logger.write(event.log);
}
let updates = {};

+ 40
- 0
web/state/logger.js View File

@ -0,0 +1,40 @@
const fs = require('fs');
const moment = require('moment');
const _ = require('lodash');
const BASEPATH = __dirname + '/../../logs/';
const Logger = function(type) {
const now = moment().utc().format('YYYY-MM-DD-HH-mm');
this.fileName = `${now}-UTC-${type}.log`;
this.writing = false;
this.queue = [];
_.bindAll(this);
}
Logger.prototype.write = function(line) {
if(!this.writing) {
this.writing = true;
fs.appendFile(
BASEPATH + this.fileName,
line + '\n',
this.handleWriteCallback
);
} else
this.queue.push(line);
}
Logger.prototype.handleWriteCallback = function(err) {
if(err)
console.error(`ERROR WRITING LOG FILE ${this.fileName}:`, err);
this.writing = false;
if(_.size(this.queue))
this.write(this.queue.shift())
}
module.exports = Logger;

Loading…
Cancel
Save