mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 18:16:45 +02:00
Fix console log not starting near the end of a file
This commit is contained in:
parent
16cf86ba6b
commit
9e9c124d0b
1 changed files with 20 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
var remote = require('electron').remote;
|
const remote = require('electron').remote;
|
||||||
var os = require('os');
|
const os = require('os');
|
||||||
var Tail = require('always-tail');
|
const fs = require('fs');
|
||||||
|
const Tail = require('always-tail');
|
||||||
|
|
||||||
function cleanPath(path) {
|
function cleanPath(path) {
|
||||||
if (os.type() == "Windows_NT") {
|
if (os.type() == "Windows_NT") {
|
||||||
|
@ -27,7 +28,7 @@ function difference(a, b) {
|
||||||
}
|
}
|
||||||
for (k of b) {
|
for (k of b) {
|
||||||
if (a.indexOf(k) == -1) {
|
if (a.indexOf(k) == -1) {
|
||||||
// In a, but not in b
|
// In b, but not in a
|
||||||
add.push(k);
|
add.push(k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,14 +66,25 @@ ready = function() {
|
||||||
diff.subtract.forEach(function(removedLogFilePath) {
|
diff.subtract.forEach(function(removedLogFilePath) {
|
||||||
watchList[removedLogFilePath].unwatch();
|
watchList[removedLogFilePath].unwatch();
|
||||||
delete watchList[removedLogFilePath];
|
delete watchList[removedLogFilePath];
|
||||||
|
console.log("Unwatching", removedLogFilePath);
|
||||||
});
|
});
|
||||||
diff.add.forEach(function(addedLogFilePath) {
|
diff.add.forEach(function(addedLogFilePath) {
|
||||||
|
const START_AT_X_BYTES_FROM_END = 0;
|
||||||
var cleanFilePath = cleanPath(addedLogFilePath);
|
var cleanFilePath = cleanPath(addedLogFilePath);
|
||||||
|
|
||||||
var logTail = new Tail(cleanFilePath, '\n', { start: 0, interval: 500 });
|
// For larger files we won't want to start tailing from the beginning of the file,
|
||||||
|
// so start `START_AT_X_BYTES_FROM_END` bytes from the end of the file.
|
||||||
|
var start = 0;
|
||||||
|
try {
|
||||||
|
var fileInfo = fs.statSync(cleanFilePath);
|
||||||
|
start = Math.max(0, fileInfo.size - START_AT_X_BYTES_FROM_END);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("ERROR READING FILE INFO", e);
|
||||||
|
}
|
||||||
|
var logTail = new Tail(cleanFilePath, '\n', { start: start, interval: 500 });
|
||||||
|
|
||||||
logTail.on('line', function(msg) {
|
logTail.on('line', function(msg) {
|
||||||
appendLogMessage(0, msg, stream);
|
appendLogMessage(msg, stream);
|
||||||
});
|
});
|
||||||
|
|
||||||
logTail.on('error', function(error) {
|
logTail.on('error', function(error) {
|
||||||
|
@ -153,7 +165,7 @@ ready = function() {
|
||||||
return !filter || message.toLowerCase().indexOf(filter) >= 0;
|
return !filter || message.toLowerCase().indexOf(filter) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendLogMessage(pid, msg, name) {
|
function appendLogMessage(msg, name) {
|
||||||
var id = name == "ds" ? "domain-server" : "assignment-client";
|
var id = name == "ds" ? "domain-server" : "assignment-client";
|
||||||
var $pidLog = $('#' + id);
|
var $pidLog = $('#' + id);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue