From 369a4eccad9671a8832a137af8986ed135c0e79d Mon Sep 17 00:00:00 2001 From: Ava Stancu Date: Thu, 8 Dec 2022 22:23:52 +0100 Subject: [PATCH] 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> --- src/Runner.Common/Terminal.cs | 9 ++++++--- src/Runner.Listener/JobDispatcher.cs | 13 +++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Runner.Common/Terminal.cs b/src/Runner.Common/Terminal.cs index bade576a0..75489bc18 100644 --- a/src/Runner.Common/Terminal.cs +++ b/src/Runner.Common/Terminal.cs @@ -18,7 +18,7 @@ namespace GitHub.Runner.Common string ReadSecret(); void Write(string message, ConsoleColor? colorCode = null); 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(string line); 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 // 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 (colorCode != null) diff --git a/src/Runner.Listener/JobDispatcher.cs b/src/Runner.Listener/JobDispatcher.cs index 1e5306bd0..aaa83b80c 100644 --- a/src/Runner.Listener/JobDispatcher.cs +++ b/src/Runner.Listener/JobDispatcher.cs @@ -400,6 +400,7 @@ namespace GitHub.Runner.Listener Task workerProcessTask = null; object _outputLock = new(); List workerOutput = new(); + bool printToStdout = StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable(Constants.Variables.Agent.PrintLogToStdout)); using (var processChannel = HostContext.CreateService()) using (var processInvoker = HostContext.CreateService()) { @@ -421,7 +422,15 @@ namespace GitHub.Runner.Listener { lock (_outputLock) { - workerOutput.Add(stdout.Data); + if (!stdout.Data.StartsWith("[WORKER")) + { + workerOutput.Add(stdout.Data); + } + + if (printToStdout) + { + term.WriteLine(stdout.Data, skipTracing: true); + } } } }; @@ -658,7 +667,7 @@ namespace GitHub.Runner.Listener finally { Busy = false; - + if (JobStatus != null) { JobStatus(this, new JobStatusEventArgs(TaskAgentStatus.Online));