From 059c6522b675636683cfd0cead250296d3bbd921 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Fri, 18 Nov 2022 17:48:20 +0100 Subject: [PATCH] Implements #37: diagnostic tools includes last lines from prosody error log files. --- CHANGELOG.md | 1 + server/lib/diagnostic/prosody.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0191536d..b7530607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ Peertube image. * Fix «autocolor» mecanism when no color provided (raised an error). * Fix #73: deleted message are shown when loading history. +* Implements #37: diagnostic tools includes last lines from prosody error log files. ## 5.7.1 diff --git a/server/lib/diagnostic/prosody.ts b/server/lib/diagnostic/prosody.ts index 13910c5f..691075a2 100644 --- a/server/lib/diagnostic/prosody.ts +++ b/server/lib/diagnostic/prosody.ts @@ -23,9 +23,11 @@ export async function diagProsody (test: string, options: RegisterServerOptions) // Testing the prosody config file. let prosodyPort: string let prosodyHost: string + let prosodyErrorLogPath: string try { const wantedConfig = await getProsodyConfig(options) const filePath = wantedConfig.paths.config + prosodyErrorLogPath = wantedConfig.paths.error result.messages.push(`Prosody will run on port '${wantedConfig.port}'`) prosodyPort = wantedConfig.port @@ -163,6 +165,27 @@ export async function diagProsody (test: string, options: RegisterServerOptions) return result } + // Checking if there is a Prosody error log, and returning last lines. + try { + await fs.promises.access(prosodyErrorLogPath, fs.constants.R_OK) // throw an error if file does not exist. + result.messages.push(`The prosody error log (${prosodyErrorLogPath}) exists`) + const errorLogContent = await fs.promises.readFile(prosodyErrorLogPath, { + encoding: 'utf-8' + }) + + let logLines = errorLogContent.split(/\r?\n/) + if (logLines.length > 50) { + logLines = logLines.slice(-50) + } + + result.debug.push({ + title: 'Prosody error log (last 50 lines)', + message: logLines.join('\n') + }) + } catch (error) { + // Error should be because file does not exists. This is not an error case, just ignoring. + } + result.ok = true return result }