Add managed thread ID to extractor log messages

This commit is contained in:
Tamas Vajk
2023-09-19 11:34:43 +02:00
parent dfd7f1e78b
commit edc93dfeb7
14 changed files with 85 additions and 107 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Semmle.Util
@@ -7,9 +8,11 @@ namespace Semmle.Util
{
/// <summary>
/// Runs this process, and returns the exit code, as well as the contents
/// of stdout in <paramref name="stdout"/>.
/// of stdout in <paramref name="stdout"/>. If <paramref name="printToConsole"/>
/// is true, then stdout is printed to the console and each line is prefixed
/// with the thread id.
/// </summary>
public static int ReadOutput(this ProcessStartInfo pi, out IList<string> stdout)
public static int ReadOutput(this ProcessStartInfo pi, out IList<string> stdout, bool printToConsole)
{
stdout = new List<string>();
using var process = Process.Start(pi);
@@ -27,6 +30,10 @@ namespace Semmle.Util
s = process.StandardOutput.ReadLine();
if (s is not null)
{
if (printToConsole)
{
Console.WriteLine($"[{Environment.CurrentManagedThreadId:D3}] {s}");
}
stdout.Add(s);
}
}