From fc3cee776f7caa47c8698d2fcd5c0d5332b82290 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 20 Jan 2016 14:51:49 -0800 Subject: [PATCH 1/3] split directory debug into two lines --- server-console/src/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server-console/src/main.js b/server-console/src/main.js index e6eba4d605..823e73db04 100644 --- a/server-console/src/main.js +++ b/server-console/src/main.js @@ -149,7 +149,8 @@ function shutdown() { var logPath = path.join(getApplicationDataDirectory(), '/logs'); -console.log("Log directory:", logPath, getRootHifiDataDirectory()); +console.log("Log directory:", logPath); +console.log("Data directory:", getRootHifiDataDirectory()); const configPath = path.join(getApplicationDataDirectory(), 'config.json'); var userConfig = new Config(); From c31ceeca863ec6a88894b64af4f874f6dc489999 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 20 Jan 2016 14:52:14 -0800 Subject: [PATCH 2/3] Add deletion of old log files --- .../src/AssignmentClientMonitor.cpp | 8 ++-- server-console/src/main.js | 44 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/assignment-client/src/AssignmentClientMonitor.cpp b/assignment-client/src/AssignmentClientMonitor.cpp index eb92522d6a..f76434d9c7 100644 --- a/assignment-client/src/AssignmentClientMonitor.cpp +++ b/assignment-client/src/AssignmentClientMonitor.cpp @@ -168,8 +168,8 @@ void AssignmentClientMonitor::spawnChildClient() { } auto nowString = QDateTime::currentDateTime().toString(DATETIME_FORMAT); - auto stdoutFilenameTemp = QString("ac_stdout_%1.txt").arg(nowString); - auto stderrFilenameTemp = QString("ac_stderr_%1.txt").arg(nowString); + auto stdoutFilenameTemp = QString("ac-%1-stdout.txt").arg(nowString); + auto stderrFilenameTemp = QString("ac-%1-stderr.txt").arg(nowString); QString stdoutPathTemp = _logDirectory.absoluteFilePath(stdoutFilenameTemp); QString stderrPathTemp = _logDirectory.absoluteFilePath(stderrFilenameTemp); @@ -183,8 +183,8 @@ void AssignmentClientMonitor::spawnChildClient() { assignmentClient->start(QCoreApplication::applicationFilePath(), _childArguments); // Update log path to use PID in filename - auto stdoutFilename = QString("ac_stdout_%1_%2.txt").arg(nowString).arg(assignmentClient->processId()); - auto stderrFilename = QString("ac_stderr_%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-%1_%2-stderr.txt").arg(nowString).arg(assignmentClient->processId()); QString stdoutPath = _logDirectory.absoluteFilePath(stdoutFilename); QString stderrPath = _logDirectory.absoluteFilePath(stderrFilename); diff --git a/server-console/src/main.js b/server-console/src/main.js index 823e73db04..34c1d82cf6 100644 --- a/server-console/src/main.js +++ b/server-console/src/main.js @@ -37,6 +37,9 @@ const osType = os.type(); 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() { 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'); + console.log("Log directory:", logPath); 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) { domainServer = new Process('domain-server', dsPath, ["--get-temp-name"], logPath); acMonitor = new ACMonitorProcess('ac-monitor', acPath, ['-n6', From b7e939bbdde49d5df7283bed1e006c944ce3b326 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 20 Jan 2016 15:00:59 -0800 Subject: [PATCH 3/3] Adjust console logs for deleting old files --- server-console/src/main.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server-console/src/main.js b/server-console/src/main.js index 34c1d82cf6..2576ac4cd3 100644 --- a/server-console/src/main.js +++ b/server-console/src/main.js @@ -162,7 +162,7 @@ function deleteOldFiles(directoryPath, maxAgeInSeconds, filenameRegex) { } for (const filename of filenames) { - console.log(filename); + console.log("Checking", filename); const absolutePath = path.join(directoryPath, filename); var stat = null; try { @@ -174,9 +174,8 @@ function deleteOldFiles(directoryPath, maxAgeInSeconds, filenameRegex) { 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); + console.log("\tDeleting:", filename, ageInSeconds); try { fs.unlinkSync(absolutePath); } catch (e) {