Made worker logs available to stdout (#2307)

* Made worker logs available to stdout

* Log Worker Standard out line by line

Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com>
This commit is contained in:
Ava Stancu
2022-12-08 22:23:52 +01:00
committed by GitHub
parent 088981a372
commit 369a4eccad
2 changed files with 17 additions and 5 deletions

View File

@@ -18,7 +18,7 @@ namespace GitHub.Runner.Common
string ReadSecret(); string ReadSecret();
void Write(string message, ConsoleColor? colorCode = null); void Write(string message, ConsoleColor? colorCode = null);
void WriteLine(); void WriteLine();
void WriteLine(string line, ConsoleColor? colorCode = null); void WriteLine(string line, ConsoleColor? colorCode = null, bool skipTracing = false);
void WriteError(Exception ex); void WriteError(Exception ex);
void WriteError(string line); void WriteError(string line);
void WriteSection(string message); void WriteSection(string message);
@@ -116,9 +116,12 @@ namespace GitHub.Runner.Common
// Do not add a format string overload. Terminal messages are user facing and therefore // Do not add a format string overload. Terminal messages are user facing and therefore
// should be localized. Use the Loc method in the StringUtil class. // should be localized. Use the Loc method in the StringUtil class.
public void WriteLine(string line, ConsoleColor? colorCode = null) public void WriteLine(string line, ConsoleColor? colorCode = null, bool skipTracing = false)
{ {
Trace.Info($"WRITE LINE: {line}"); if (!skipTracing)
{
Trace.Info($"WRITE LINE: {line}");
}
if (!Silent) if (!Silent)
{ {
if (colorCode != null) if (colorCode != null)

View File

@@ -400,6 +400,7 @@ namespace GitHub.Runner.Listener
Task<int> workerProcessTask = null; Task<int> workerProcessTask = null;
object _outputLock = new(); object _outputLock = new();
List<string> workerOutput = new(); List<string> workerOutput = new();
bool printToStdout = StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable(Constants.Variables.Agent.PrintLogToStdout));
using (var processChannel = HostContext.CreateService<IProcessChannel>()) using (var processChannel = HostContext.CreateService<IProcessChannel>())
using (var processInvoker = HostContext.CreateService<IProcessInvoker>()) using (var processInvoker = HostContext.CreateService<IProcessInvoker>())
{ {
@@ -421,7 +422,15 @@ namespace GitHub.Runner.Listener
{ {
lock (_outputLock) lock (_outputLock)
{ {
workerOutput.Add(stdout.Data); if (!stdout.Data.StartsWith("[WORKER"))
{
workerOutput.Add(stdout.Data);
}
if (printToStdout)
{
term.WriteLine(stdout.Data, skipTracing: true);
}
} }
} }
}; };