mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-26 01:35:14 +02:00
Add deletion of old log files
This commit is contained in:
parent
fc3cee776f
commit
c31ceeca86
2 changed files with 48 additions and 4 deletions
|
@ -168,8 +168,8 @@ void AssignmentClientMonitor::spawnChildClient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nowString = QDateTime::currentDateTime().toString(DATETIME_FORMAT);
|
auto nowString = QDateTime::currentDateTime().toString(DATETIME_FORMAT);
|
||||||
auto stdoutFilenameTemp = QString("ac_stdout_%1.txt").arg(nowString);
|
auto stdoutFilenameTemp = QString("ac-%1-stdout.txt").arg(nowString);
|
||||||
auto stderrFilenameTemp = QString("ac_stderr_%1.txt").arg(nowString);
|
auto stderrFilenameTemp = QString("ac-%1-stderr.txt").arg(nowString);
|
||||||
QString stdoutPathTemp = _logDirectory.absoluteFilePath(stdoutFilenameTemp);
|
QString stdoutPathTemp = _logDirectory.absoluteFilePath(stdoutFilenameTemp);
|
||||||
QString stderrPathTemp = _logDirectory.absoluteFilePath(stderrFilenameTemp);
|
QString stderrPathTemp = _logDirectory.absoluteFilePath(stderrFilenameTemp);
|
||||||
|
|
||||||
|
@ -183,8 +183,8 @@ void AssignmentClientMonitor::spawnChildClient() {
|
||||||
assignmentClient->start(QCoreApplication::applicationFilePath(), _childArguments);
|
assignmentClient->start(QCoreApplication::applicationFilePath(), _childArguments);
|
||||||
|
|
||||||
// Update log path to use PID in filename
|
// Update log path to use PID in filename
|
||||||
auto stdoutFilename = QString("ac_stdout_%1_%2.txt").arg(nowString).arg(assignmentClient->processId());
|
auto stdoutFilename = QString("ac-%1_%2-stdout.txt").arg(nowString).arg(assignmentClient->processId());
|
||||||
auto stderrFilename = QString("ac_stderr_%1_%2.txt").arg(nowString).arg(assignmentClient->processId());
|
auto stderrFilename = QString("ac-%1_%2-stderr.txt").arg(nowString).arg(assignmentClient->processId());
|
||||||
QString stdoutPath = _logDirectory.absoluteFilePath(stdoutFilename);
|
QString stdoutPath = _logDirectory.absoluteFilePath(stdoutFilename);
|
||||||
QString stderrPath = _logDirectory.absoluteFilePath(stderrFilename);
|
QString stderrPath = _logDirectory.absoluteFilePath(stderrFilename);
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,9 @@ const osType = os.type();
|
||||||
|
|
||||||
const appIcon = path.join(__dirname, '../resources/console.png');
|
const appIcon = path.join(__dirname, '../resources/console.png');
|
||||||
|
|
||||||
|
const DELETE_LOG_FILES_OLDER_THAN_X_SECONDS = 60 * 60 * 24 * 7; // 7 Days
|
||||||
|
const LOG_FILE_REGEX = /(domain-server|ac-monitor|ac)-.*-std(out|err).txt/;
|
||||||
|
|
||||||
function getBuildInfo() {
|
function getBuildInfo() {
|
||||||
var buildInfoPath = null;
|
var buildInfoPath = null;
|
||||||
|
|
||||||
|
@ -147,8 +150,47 @@ function shutdown() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteOldFiles(directoryPath, maxAgeInSeconds, filenameRegex) {
|
||||||
|
console.log("Deleting old log files in " + directoryPath);
|
||||||
|
|
||||||
|
var filenames = [];
|
||||||
|
try {
|
||||||
|
filenames = fs.readdirSync(directoryPath);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Error reading contents of log file directory", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const filename of filenames) {
|
||||||
|
console.log(filename);
|
||||||
|
const absolutePath = path.join(directoryPath, filename);
|
||||||
|
var stat = null;
|
||||||
|
try {
|
||||||
|
stat = fs.statSync(absolutePath);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Error stat'ing file", absolutePath, e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const curTime = Date.now();
|
||||||
|
if (stat.isFile() && filename.search(filenameRegex) >= 0) {
|
||||||
|
const ageInSeconds = (curTime - stat.mtime.getTime()) / 1000.0;
|
||||||
|
console.log("Match:", filename, ageInSeconds);
|
||||||
|
if (ageInSeconds >= maxAgeInSeconds) {
|
||||||
|
console.log("\tDeleting:", filename);
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(absolutePath);
|
||||||
|
} catch (e) {
|
||||||
|
if (e.code != 'EBUSY') {
|
||||||
|
console.warn("\tError deleting:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var logPath = path.join(getApplicationDataDirectory(), '/logs');
|
var logPath = path.join(getApplicationDataDirectory(), '/logs');
|
||||||
|
|
||||||
console.log("Log directory:", logPath);
|
console.log("Log directory:", logPath);
|
||||||
console.log("Data directory:", getRootHifiDataDirectory());
|
console.log("Data directory:", getRootHifiDataDirectory());
|
||||||
|
|
||||||
|
@ -612,6 +654,8 @@ app.on('ready', function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteOldFiles(logPath, DELETE_LOG_FILES_OLDER_THAN_X_SECONDS, LOG_FILE_REGEX);
|
||||||
|
|
||||||
if (dsPath && acPath) {
|
if (dsPath && acPath) {
|
||||||
domainServer = new Process('domain-server', dsPath, ["--get-temp-name"], logPath);
|
domainServer = new Process('domain-server', dsPath, ["--get-temp-name"], logPath);
|
||||||
acMonitor = new ACMonitorProcess('ac-monitor', acPath, ['-n6',
|
acMonitor = new ACMonitorProcess('ac-monitor', acPath, ['-n6',
|
||||||
|
|
Loading…
Reference in a new issue