Skip to content

Commit 39108f2

Browse files
Add new env var to allow single-prefix multiline logs on stdout (#4424)
Co-authored-by: Tingluo Huang <tingluohuang@github.com>
1 parent 7e0ff4d commit 39108f2

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/Runner.Common/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ public static class Agent
308308
public static readonly string ForcedInternalNodeVersion = "ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION";
309309
public static readonly string ForcedActionsNodeVersion = "ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION";
310310
public static readonly string PrintLogToStdout = "ACTIONS_RUNNER_PRINT_LOG_TO_STDOUT";
311+
public static readonly string DisableStdoutMultilineLogPrefixing = "ACTIONS_RUNNER_DISABLE_STDOUT_MULTILINE_LOG_PREFIXING";
311312
public static readonly string ActionArchiveCacheDirectory = "ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE";
312313
public static readonly string SymlinkCachedActions = "ACTIONS_RUNNER_SYMLINK_CACHED_ACTIONS";
313314
public static readonly string EmitCompositeMarkers = "ACTIONS_RUNNER_EMIT_COMPOSITE_MARKERS";

src/Runner.Common/StdoutTraceListener.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Diagnostics;
33
using System.Globalization;
44
using System.IO;
@@ -9,10 +9,12 @@ namespace GitHub.Runner.Common
99
public sealed class StdoutTraceListener : ConsoleTraceListener
1010
{
1111
private readonly string _hostType;
12+
private readonly bool _disablePrefixMultilineLogs = false;
1213

1314
public StdoutTraceListener(string hostType)
1415
{
1516
this._hostType = hostType;
17+
this._disablePrefixMultilineLogs = StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable(Constants.Variables.Agent.DisableStdoutMultilineLogPrefixing));
1618
}
1719

1820
// 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
2628

2729
if (!string.IsNullOrEmpty(message))
2830
{
29-
var messageLines = message.Split(Environment.NewLine);
30-
foreach (var messageLine in messageLines)
31+
if (!this._disablePrefixMultilineLogs)
32+
{
33+
var messageLines = message.Split(Environment.NewLine);
34+
foreach (var messageLine in messageLines)
35+
{
36+
WriteHeader(source, eventType, id);
37+
WriteLine(messageLine);
38+
WriteFooter(eventCache);
39+
}
40+
}
41+
else
3142
{
3243
WriteHeader(source, eventType, id);
33-
WriteLine(messageLine);
44+
WriteLine(message);
3445
WriteFooter(eventCache);
3546
}
3647
}

0 commit comments

Comments
 (0)