LAPI-310: Update error logs

This commit is contained in:
Sergiu Toma 2019-10-09 11:26:26 +03:00
parent cd1ba63c5a
commit bbcaea217e
5 changed files with 36 additions and 21 deletions

View File

@ -7,7 +7,7 @@ address = 'https://hub.presgold.linx.safemobile.com/'
[api] [api]
port = '' port = ''
host = 'presgold.linx.safemobile.com/apii' host = 'presgold.linx.safemobile.com/api'
use_secure = true use_secure = true
accept_untrusted_certs = true accept_untrusted_certs = true

View File

@ -41,7 +41,7 @@ class Asset {
utils.writeLog(`Asset ${this.id} was successfully initialized`) utils.writeLog(`Asset ${this.id} was successfully initialized`)
if (err) { if (err) {
utils.writeErrorLog(`Asset ${this.id} was not successfully initialized`, err); utils.writeLog(`Asset ${this.id} was not successfully initialized`, err);
return; return;
} }
@ -85,7 +85,8 @@ class Asset {
return this._getGroupsFromApi(callback); return this._getGroupsFromApi(callback);
} else { } else {
utils.writeErrorLog(`ERROR getting informations about asset ${this.id}`, error); utils.writeLog(`ERROR getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API`);
return callback(error); return callback(error);
} }
} }
@ -119,7 +120,8 @@ class Asset {
utils.writeLog(`Informations about asset ${this.id} received`) utils.writeLog(`Informations about asset ${this.id} received`)
return callback(); return callback();
} else { } else {
utils.writeErrorLog(`Error getting informations about asset ${this.id}`, error); utils.writeLog(`Error getting informations about asset ${this.id}`, error);
utils.writeErrorLog(`ERROR_API`);
return callback(error); return callback(error);
} }
} }
@ -135,18 +137,24 @@ class Asset {
// Disconnect event // Disconnect event
hub.on('disconnect', () => { hub.on('disconnect', () => {
utils.writeLog(`Asset ${this.id} disconnected from HUB`) utils.writeLog(`Asset ${this.id} disconnected from HUB`);
}); });
let err = (e) => {
utils.writeErrorLog(`Asset ${this.id} HUB connection error ${e}`); hub.on('connect_timeout', () => {
} utils.writeLog(`Asset ${this.id} connect_timeout from HUB`);
hub.on('connect_timeout', err); utils.writeErrorLog(`ERROR_HUB`);
hub.on('connect_error', err); });
hub.on('connect_error', () => {
utils.writeLog(`Asset ${this.id} connect_error from HUB`);
utils.writeErrorLog(`ERROR_HUB`);
});
hub.once('connect', () => { hub.once('connect', () => {
return callback(); return callback();
}); });
hub.on('connect', () => { hub.on('connect', () => {
utils.writeLog(`Asset ${this.id} connected to HUB`) utils.writeLog(`Asset ${this.id} connected to HUB`);
this._sendArs(); this._sendArs();
}); });
@ -182,7 +190,8 @@ class Asset {
this.mumble = new Mumble(this.id, this.configs, (err) => { this.mumble = new Mumble(this.id, this.configs, (err) => {
if (err) { if (err) {
utils.writeErrorLog(`Asset ${this.id} Murmur connection error`, err); utils.writeLog(`Asset ${this.id} Murmur connection error`, err);
utils.writeErrorLog(`ERROR_MURMUR`);
return callback(err); return callback(err);
} else { } else {
return callback(); return callback();
@ -203,7 +212,8 @@ class Asset {
utils.writeLog(`Asset ${this.id} audio registered`); utils.writeLog(`Asset ${this.id} audio registered`);
return callback(); return callback();
} else { } else {
utils.writeErrorLog(`Asset ${this.id} audio registered error`, error); utils.writeLog(`Asset ${this.id} audio registered error`, error);
utils.writeErrorLog(`ERROR_API`);
return callback(error); return callback(error);
} }
} }
@ -239,7 +249,8 @@ class Asset {
return callback('Cannot send group-monitoring: Hub not connected'); return callback('Cannot send group-monitoring: Hub not connected');
} }
} else { } else {
utils.writeErrorLog(`Asset ${this.id} audio enter group error`, error); utils.writeLog(`Asset ${this.id} audio enter group error`, error);
utils.writeErrorLog(`ERROR_API`);
return callback(error); return callback(error);
} }
} }
@ -291,7 +302,8 @@ class Asset {
console.log(chalk.yellow(`[RECORDER] for asset ${this.id} not found`)); console.log(chalk.yellow(`[RECORDER] for asset ${this.id} not found`));
} }
} else { } else {
utils.writeErrorLog(`Error getting record for asset ${this.id}`); utils.writeLog(`Error getting record for asset ${this.id}`);
utils.writeErrorLog(`ERROR_RECORDER`);
throw error; throw error;
} }
@ -337,6 +349,7 @@ class Asset {
mp3.on('error', (e) => { mp3.on('error', (e) => {
utils.writeErrorLog(`Error _makePtt asset ${this.id}`, e); utils.writeErrorLog(`Error _makePtt asset ${this.id}`, e);
}); });
mp3.on('data', (data) => { mp3.on('data', (data) => {
}); });

View File

@ -17,7 +17,6 @@ class Mumble {
this.configs = configs; this.configs = configs;
let mumble = configs.mumble; let mumble = configs.mumble;
this._createCertificatesForUser(id, () => { this._createCertificatesForUser(id, () => {
this._makeMumbleConnection(id, mumble.port, mumble.host, id, id, connectedCallback); this._makeMumbleConnection(id, mumble.port, mumble.host, id, id, connectedCallback);
}) })
} }
@ -31,7 +30,7 @@ class Mumble {
if (!fs.existsSync(path)) { if (!fs.existsSync(path)) {
utils.writeLog(`Creating certificates for asset ${id}`) utils.writeLog(`Creating certificates for asset ${id}`)
try { try {
var code = execSync(currentPath + '/createCerts.sh ' + id); code = execSync(currentPath + '/createCerts.sh ' + id);
} catch (e) { } catch (e) {
return callback(false); return callback(false);
} }
@ -50,7 +49,8 @@ class Mumble {
utils.writeLog(`Creating certificates for Mumble`); utils.writeLog(`Creating certificates for Mumble`);
try { execSync('./createCA.sh'); } try { execSync('./createCA.sh'); }
catch(e) { catch(e) {
utils.writeErrorLog(`Could not crete Mumble certificates. Error:${e}`); utils.writeLog(`Could not crete Mumble certificates. Error:${e}`);
utils.writeErrorLog(`ERROR_MUMBLE`);
throw 'Could not crete CA certificates. ' + e; throw 'Could not crete CA certificates. ' + e;
} }
} else { } else {
@ -113,8 +113,8 @@ class Mumble {
// never forget // never forget
// console.log(err) // console.log(err)
// connectedCallback(err); // connectedCallback(err);
console.log('Mumble _makeMumbleConnection ERROR') utils.writeLog('Mumble _makeMumbleConnection ERROR', err);
utils.writeErrorLog('Mumble _makeMumbleConnection ERROR', err); utils.writeErrorLog(`ERROR_MUMBLE`);
}) })
.connect({ port: port, host: host, rejectUnauthorized: false, secureContext: secureContext }); .connect({ port: port, host: host, rejectUnauthorized: false, secureContext: secureContext });
} }

View File

@ -62,7 +62,8 @@ class Simulator {
utils.writeLog(`Unregister assets: ${this.assetIds}`) utils.writeLog(`Unregister assets: ${this.assetIds}`)
return callback(); return callback();
} else { } else {
utils.writeErrorLog(`ERROR can't unregister users ${this.assetIds}`, error); utils.writeLog(`ERROR can't unregister users ${this.assetIds}`, error);
utils.writeErrorLog(`ERROR_API`);
return callback(error); return callback(error);
} }
} }

View File

@ -12,6 +12,7 @@ module.exports.writeLog = async (value) => {
module.exports.writeErrorLog = async (value) => { module.exports.writeErrorLog = async (value) => {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
console.log(`ERROR: ${value}`);
await fs.writeFile('./logs/error.log', `[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${value}\n`, {'flag':'a'}, (err) => { await fs.writeFile('./logs/error.log', `[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${value}\n`, {'flag':'a'}, (err) => {
if (err) { reject(err); } if (err) { reject(err); }
else { resolve(); } else { resolve(); }