diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index 42f6e714781..8536e942a27 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -308,6 +308,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 DisableStdoutMultilineLogPrefixing = "ACTIONS_RUNNER_DISABLE_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..81d36cadc9b 100644 --- a/src/Runner.Common/StdoutTraceListener.cs +++ b/src/Runner.Common/StdoutTraceListener.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.Globalization; using System.IO; @@ -9,10 +9,12 @@ namespace GitHub.Runner.Common public sealed class StdoutTraceListener : ConsoleTraceListener { private readonly string _hostType; + private readonly bool _disablePrefixMultilineLogs = false; public StdoutTraceListener(string hostType) { this._hostType = hostType; + this._disablePrefixMultilineLogs = StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable(Constants.Variables.Agent.DisableStdoutMultilineLogPrefixing)); } // Copied and modified slightly from .Net Core source code. Modification was required to make it compile. @@ -26,11 +28,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._disablePrefixMultilineLogs) + { + 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); } }