From 648daffb1f6d81c1a6789d230ed815478f4b9aa8 Mon Sep 17 00:00:00 2001 From: Stewart Webb Date: Fri, 15 May 2026 22:19:07 +1000 Subject: [PATCH] add new env var to allow stdout logs to not have header for every single line of multiline messages --- src/Runner.Common/Constants.cs | 1 + src/Runner.Common/StdoutTraceListener.cs | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index 7a1f1cbb0a1..b1ce0eb3606 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -307,6 +307,7 @@ public static class Agent public static readonly string ForcedInternalNodeVersion = "ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION"; public static readonly string ForcedActionsNodeVersion = "ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION"; public static readonly string PrintLogToStdout = "ACTIONS_RUNNER_PRINT_LOG_TO_STDOUT"; + public static readonly string StdoutMultilineLogPrefixing = "ACTIONS_RUNNER_STDOUT_MULTILINE_LOG_PREFIXING"; public static readonly string ActionArchiveCacheDirectory = "ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE"; public static readonly string SymlinkCachedActions = "ACTIONS_RUNNER_SYMLINK_CACHED_ACTIONS"; public static readonly string EmitCompositeMarkers = "ACTIONS_RUNNER_EMIT_COMPOSITE_MARKERS"; diff --git a/src/Runner.Common/StdoutTraceListener.cs b/src/Runner.Common/StdoutTraceListener.cs index 150263ac77c..1c1d77a0781 100644 --- a/src/Runner.Common/StdoutTraceListener.cs +++ b/src/Runner.Common/StdoutTraceListener.cs @@ -9,10 +9,18 @@ namespace GitHub.Runner.Common public sealed class StdoutTraceListener : ConsoleTraceListener { private readonly string _hostType; + private readonly bool _prefixMultilineLogs = true; public StdoutTraceListener(string hostType) { this._hostType = hostType; + // The stdout log prefixing behaviour was on before this environment variable, + // so only disable it if the env var was set + bool multilinePrefixingEnvSetting = StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable(Constants.Variables.Agent.StdoutMultilineLogPrefixing), defaultValue: true); + if (!multilinePrefixingEnvSetting) + { + this._prefixMultilineLogs = false; + } } // Copied and modified slightly from .Net Core source code. Modification was required to make it compile. @@ -26,11 +34,20 @@ public override void TraceEvent(TraceEventCache eventCache, string source, Trace if (!string.IsNullOrEmpty(message)) { - var messageLines = message.Split(Environment.NewLine); - foreach (var messageLine in messageLines) + if (this._prefixMultilineLogs) + { + var messageLines = message.Split(Environment.NewLine); + foreach (var messageLine in messageLines) + { + WriteHeader(source, eventType, id); + WriteLine(messageLine); + WriteFooter(eventCache); + } + } + else { WriteHeader(source, eventType, id); - WriteLine(messageLine); + WriteLine(message); WriteFooter(eventCache); } }