Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made worker logs available to stdout #2307

Merged
merged 2 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Runner.Common/Terminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ITerminal : IRunnerService, IDisposable
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);
Expand Down Expand Up @@ -116,9 +116,12 @@ public void WriteLine()

// 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)
Expand Down
13 changes: 11 additions & 2 deletions src/Runner.Listener/JobDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ private async Task RunAsync(Pipelines.AgentJobRequestMessage message, string orc
Task<int> workerProcessTask = null;
object _outputLock = new();
List<string> workerOutput = new();
bool printToStdout = StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable(Constants.Variables.Agent.PrintLogToStdout));
using (var processChannel = HostContext.CreateService<IProcessChannel>())
using (var processInvoker = HostContext.CreateService<IProcessInvoker>())
{
Expand All @@ -421,7 +422,15 @@ private async Task RunAsync(Pipelines.AgentJobRequestMessage message, string orc
{
lock (_outputLock)
{
workerOutput.Add(stdout.Data);
if (!stdout.Data.StartsWith("[WORKER"))
{
workerOutput.Add(stdout.Data);
}

if (printToStdout)
{
term.WriteLine(stdout.Data, skipTracing: true);
}
}
}
};
Expand Down Expand Up @@ -658,7 +667,7 @@ await processChannel.SendAsync(
finally
{
Busy = false;

if (JobStatus != null)
{
JobStatus(this, new JobStatusEventArgs(TaskAgentStatus.Online));
Expand Down