From f307255e694d290c346749bff68545d5dfc581cf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 7 Dec 2021 15:20:03 +0100 Subject: Display server logs when server run fails --- shared/extra-utils/server/server.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts index 31224ebe9..9da293877 100644 --- a/shared/extra-utils/server/server.ts +++ b/shared/extra-utils/server/server.ts @@ -220,10 +220,11 @@ export class PeerTubeServer { return new Promise((res, rej) => { const self = this + let aggregatedLogs = '' this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions) - const onPeerTubeExit = () => rej(new Error('Process exited')) + const onPeerTubeExit = () => rej(new Error('Process exited:\n' + aggregatedLogs)) const onParentExit = () => { if (!this.app || !this.app.pid) return @@ -238,10 +239,13 @@ export class PeerTubeServer { this.app.stdout.on('data', function onStdout (data) { let dontContinue = false + const log: string = data.toString() + aggregatedLogs += log + // Capture things if we want to for (const key of Object.keys(regexps)) { const regexp = regexps[key] - const matches = data.toString().match(regexp) + const matches = log.match(regexp) if (matches !== null) { if (key === 'client_id') self.store.client.id = matches[1] else if (key === 'client_secret') self.store.client.secret = matches[1] @@ -252,7 +256,7 @@ export class PeerTubeServer { // Check if all required sentences are here for (const key of Object.keys(serverRunString)) { - if (data.toString().indexOf(key) !== -1) serverRunString[key] = true + if (log.includes(key)) serverRunString[key] = true if (serverRunString[key] === false) dontContinue = true } @@ -260,7 +264,7 @@ export class PeerTubeServer { if (dontContinue === true) return if (options.hideLogs === false) { - console.log(data.toString()) + console.log(log) } else { process.removeListener('exit', onParentExit) self.app.stdout.removeListener('data', onStdout) -- cgit v1.2.3