From efd0936a6710adba1d28dafb5e27cd448f941214 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 16 Jun 2023 14:29:40 -0400 Subject: [PATCH] Always log DreamDaemon output under test --- .../Session/SessionControllerFactory.cs | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs index 586af39cd4..f9921dc324 100644 --- a/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs @@ -286,6 +286,7 @@ namespace Tgstation.Server.Host.Components.Session await CheckPagerIsNotRunning(cancellationToken); string outputFilePath = null; + var preserveLogFile = true; if (launchParameters.LogOutput.Value) { var now = DateTimeOffset.UtcNow; @@ -299,7 +300,10 @@ namespace Tgstation.Server.Host.Components.Session logger.LogInformation("Logging DreamDaemon output to {path}...", outputFilePath); } else if (!byondLock.SupportsCli) + { outputFilePath = gameIOManager.ConcatPath(dmbProvider.Directory, $"{Guid.NewGuid()}.dd.log"); + preserveLogFile = false; + } var accessIdentifier = cryptographySuite.GetSecureString(); @@ -352,9 +356,12 @@ namespace Tgstation.Server.Host.Components.Session assemblyInformationProvider, asyncDelayer, loggerFactory.CreateLogger(), - () => !launchParameters.LogOutput.Value - ? LogDDOutput(process, outputFilePath, byondLock.SupportsCli, default) // DCT: None available - : Task.CompletedTask, + () => LogDDOutput( + process, + outputFilePath, + byondLock.SupportsCli, + preserveLogFile, + default), // DCT: None available launchParameters.StartupTimeout, false, apiValidate); @@ -562,18 +569,20 @@ namespace Tgstation.Server.Host.Components.Session /// Attempts to log DreamDaemon output. /// /// The DreamDaemon . - /// The path to the DreamDaemon log file. Will be deleted. + /// The path to the DreamDaemon log file. Will be deleted if is . /// If DreamDaemon was launched with CLI capabilities. + /// If , will be deleted. /// The for the operation. /// A representing the running operation. - async Task LogDDOutput(IProcess process, string outputFilePath, bool cliSupported, CancellationToken cancellationToken) + async Task LogDDOutput(IProcess process, string outputFilePath, bool cliSupported, bool preserveFile, CancellationToken cancellationToken) { try { - string ddOutput; + string ddOutput = null; if (cliSupported) ddOutput = await process.GetCombinedOutput(cancellationToken); - else + + if (ddOutput == null) try { var dreamDaemonLogBytes = await gameIOManager.ReadAllBytes( @@ -584,14 +593,16 @@ namespace Tgstation.Server.Host.Components.Session } finally { - try - { - await gameIOManager.DeleteFile(outputFilePath, cancellationToken); - } - catch (Exception ex) - { - logger.LogWarning(ex, "Failed to delete DreamDaemon log file {outputFilePath}!", outputFilePath); - } + if (!preserveFile) + try + { + logger.LogTrace("Deleting temporary log file {path}...", outputFilePath); + await gameIOManager.DeleteFile(outputFilePath, cancellationToken); + } + catch (Exception ex) + { + logger.LogWarning(ex, "Failed to delete DreamDaemon log file {outputFilePath}!", outputFilePath); + } } logger.LogTrace(