File Logger

This commit is contained in:
portree_kid 2020-07-06 22:06:23 +02:00
parent 70926ed2ff
commit 760c7e4fd0
5 changed files with 58 additions and 10 deletions

View File

@ -80,7 +80,7 @@
worker.progress = 0 worker.progress = 0
// var worker = new Worker(fileUrl('src/renderer/utils/worker.js')) // var worker = new Worker(fileUrl('src/renderer/utils/worker.js'))
this.worker = worker this.worker = worker
worker.postMessage(['scanapt', this.$store.state.Settings.settings.flightgearDirectory_apt]) worker.postMessage(['scanapt', this.$store.state.Settings.settings.flightgearDirectory_apt, this.$store.state.Settings.settings.scanLogging])
this.pollData() this.pollData()
// the reply // the reply
var store = this.$store var store = this.$store
@ -127,7 +127,7 @@
worker.progress = 0 worker.progress = 0
this.worker = worker this.worker = worker
worker.postMessage(['scan', this.$store.state.Settings.settings.airportsDirectory]) worker.postMessage(['scan', this.$store.state.Settings.settings.airportsDirectory, this.$store.state.Settings.settings.scanLogging])
this.pollData() this.pollData()
// the reply // the reply
var store = this.$store var store = this.$store
@ -174,7 +174,7 @@
worker.max = this.max worker.max = this.max
worker.progress = this.progress worker.progress = this.progress
this.worker = worker this.worker = worker
worker.postMessage(['scanai', this.$store.state.Settings.settings.flightgearDirectory_traffic]) worker.postMessage(['scanai', this.$store.state.Settings.settings.flightgearDirectory_traffic, this.$store.state.Settings.settings.scanLogging])
this.pollData() this.pollData()
// the reply // the reply
var store = this.$store var store = this.$store

View File

@ -82,6 +82,22 @@
</el-popover> </el-popover>
</el-col> </el-col>
</el-row> </el-row>
<el-row>
<el-col :span="7">
<span class="label">Scan logging :</span>
</el-col>
<el-col :span="15">
<el-popover
placement="top-start"
title="Logging"
width="200"
trigger="hover"
content="Switch on logging for scan. Big performance hit"
>
<el-switch v-model="scanLogging" slot="reference"></el-switch>
</el-popover>
</el-col>
</el-row>
<el-row> <el-row>
<el-col :span="7" class="label"></el-col> <el-col :span="7" class="label"></el-col>
<el-col :span="17"> <el-col :span="17">
@ -184,6 +200,16 @@
}, },
test_directory: function () { test_directory: function () {
return this.$store.state.Settings.settings.testDirectory return this.$store.state.Settings.settings.testDirectory
},
scanLogging: {
// getter
get: function () {
return this.$store.state.Settings.settings.scanLogging === 1
},
// setter
set: function (newValue) {
this.$store.commit('SET_SCAN_LOGGING', newValue ? 1 : 0)
}
} }
} }
} }

View File

@ -38,7 +38,10 @@ const mutations = {
}, },
'SET_PHI_URL' (state, phi_url) { 'SET_PHI_URL' (state, phi_url) {
state.settings.phi_url = phi_url state.settings.phi_url = phi_url
}, },
'SET_SCAN_LOGGING' (state, scanLogging) {
state.settings.scanLogging = scanLogging
},
'ADD_WIP' (state, airport) { 'ADD_WIP' (state, airport) {
const item = state.wip.find((e) => e.icao === airport.icao) const item = state.wip.find((e) => e.icao === airport.icao)
airport.time = Date.now() airport.time = Date.now()

View File

@ -1,4 +1,4 @@
var util = require("util") var util = require("util");
const d = new Date(); const d = new Date();
@ -10,12 +10,20 @@ const fName = 'scan_' + d.getFullYear()
+ d.getSeconds() + d.getSeconds()
+ d.getMilliseconds() + '.log'; + d.getMilliseconds() + '.log';
var logStream = require('fs').createWriteStream( fName, {autoClose: true}); var logStream = null;
var loggerInit = function (logging) {
if (logging) {
logStream = require('fs').createWriteStream( fName, {autoClose: true});
}
}
var logger = function (level, msg, o) { var logger = function (level, msg, o) {
var d = new Date(); var d = new Date();
//logStream.write(d.toUTCString() + '|' + level + ' | ' + msg + '\r\n'); if(logStream!==null) {
if (o != undefined) { logStream.write(d.toUTCString() + '|' + level + ' | ' + msg + '\r\n');
//logStream.write( util.inspect(o,{depth: 2}) + '\r\n'); }
if (o != undefined && logStream!==null) {
logStream.write( util.inspect(o,{depth: 2}) + '\r\n');
} }
} }

View File

@ -19,9 +19,10 @@ function errorReceiver(event) {
onmessage = function (event) { onmessage = function (event) {
postMessage('scanStarted'); postMessage('scanStarted');
logger('info', 'Scan Started');
console.log(event.data); console.log(event.data);
if (event.data[0] === 'scan') { if (event.data[0] === 'scan') {
loggerInit(event.data[2]);
logger('info', 'Scan Groundnet Started');
scanGroundnet(event.data[1]).then(result => { scanGroundnet(event.data[1]).then(result => {
console.log("DONE Scanning"); console.log("DONE Scanning");
postMessage('DONE'); postMessage('DONE');
@ -30,9 +31,13 @@ onmessage = function (event) {
).catch(result => { ).catch(result => {
console.log('Crashed'); console.log('Crashed');
console.log(result); console.log(result);
logger('error', 'crashed');
logger('error', result);
postMessage('DONE'); postMessage('DONE');
}); });
} else if (event.data[0] === 'scanai') { } else if (event.data[0] === 'scanai') {
loggerInit(event.data[2]);
logger('info', 'Scan AI Started');
scanai(event.data[1]).then(result => { scanai(event.data[1]).then(result => {
console.log("DONE Scanning"); console.log("DONE Scanning");
postMessage('DONE'); postMessage('DONE');
@ -41,10 +46,14 @@ onmessage = function (event) {
).catch(result => { ).catch(result => {
console.log('Crashed'); console.log('Crashed');
console.log(result); console.log(result);
logger('error', 'crashed');
logger('error', result);
postMessage('DONE'); postMessage('DONE');
}); });
} }
else if (event.data[0] === 'scanapt') { else if (event.data[0] === 'scanapt') {
loggerInit(event.data[2]);
logger('info', 'Scan APT Started');
scanAPT(event.data[1]).then(result => { scanAPT(event.data[1]).then(result => {
console.log("DONE Scanning"); console.log("DONE Scanning");
postMessage('DONE'); postMessage('DONE');
@ -53,6 +62,8 @@ onmessage = function (event) {
).catch(result => { ).catch(result => {
console.log('Crashed'); console.log('Crashed');
console.log(result); console.log(result);
logger('error', 'crashed');
logger('error', result);
postMessage('DONE'); postMessage('DONE');
}); });