Skip to content

Commit a2656af

Browse files
authored
Add timestamps to XUnitLogChecker output (#86737)
* Add timestamps to XUnitLogChecker output * format * Handle $ strings * Combine two Writes into one
1 parent eb09ba9 commit a2656af

1 file changed

Lines changed: 39 additions & 37 deletions

File tree

src/tests/Common/XUnitLogChecker/XUnitLogChecker.cs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ static int Main(string[] args)
4040
{
4141
if (args.Length < 2)
4242
{
43-
Console.WriteLine("[XUnitLogChecker]: The path to the log file and"
44-
+ " the name of the wrapper are required for an"
45-
+ " accurate check and fixing.");
43+
WriteLineTimestamp("The path to the log file and"
44+
+ " the name of the wrapper are required for an"
45+
+ " accurate check and fixing.");
4646
return MISSING_ARGS;
4747
}
4848

@@ -64,8 +64,7 @@ static int Main(string[] args)
6464

6565
if (File.Exists(finalLogPath))
6666
{
67-
Console.WriteLine($"[XUnitLogChecker]: Item '{wrapperName}' did"
68-
+ " complete successfully!");
67+
WriteLineTimestamp($"Item '{wrapperName}' did complete successfully!");
6968
return SUCCESS;
7069
}
7170

@@ -80,11 +79,11 @@ static int Main(string[] args)
8079

8180
if (!File.Exists(tempLogPath))
8281
{
83-
Console.WriteLine("[XUnitLogChecker]: No logs were found. This work"
84-
+ " item was skipped.");
85-
Console.WriteLine($"[XUnitLogChecker]: If this is a mistake, then"
86-
+ " something went very wrong. The expected temp"
87-
+ $" log name would be: '{tempLogName}'");
82+
WriteLineTimestamp("No logs were found. This work"
83+
+ " item was skipped.");
84+
WriteLineTimestamp($"If this is a mistake, then"
85+
+ " something went very wrong. The expected temp"
86+
+ $" log name would be: '{tempLogName}'");
8887
return SUCCESS;
8988
}
9089

@@ -95,8 +94,8 @@ static int Main(string[] args)
9594

9695
if (!File.Exists(statsCsvPath))
9796
{
98-
Console.WriteLine("[XUnitLogChecker]: An error occurred. No stats csv"
99-
+ $" was found. The expected name would be '{statsCsvPath}'.");
97+
WriteLineTimestamp("An error occurred. No stats csv"
98+
+ $" was found. The expected name would be '{statsCsvPath}'.");
10099
return FAILURE;
101100
}
102101

@@ -105,8 +104,8 @@ static int Main(string[] args)
105104

106105
if (workItemStats is null)
107106
{
108-
Console.WriteLine("[XUnitLogChecker]: Timed out trying to read the"
109-
+ $" stats file '{statsCsvPath}'.");
107+
WriteLineTimestamp("Timed out trying to read the"
108+
+ $" stats file '{statsCsvPath}'.");
110109
return FAILURE;
111110
}
112111

@@ -128,13 +127,13 @@ static int Main(string[] args)
128127
.ToArray();
129128

130129
// Here goes the main core of the XUnit Log Checker :)
131-
Console.WriteLine($"[XUnitLogChecker]: Item '{wrapperName}' did not"
132-
+ " finish running. Checking and fixing the log...");
130+
WriteLineTimestamp($"Item '{wrapperName}' did not"
131+
+ " finish running. Checking and fixing the log...");
133132

134133
bool success = FixTheXml(tempLogPath);
135134
if (!success)
136135
{
137-
Console.WriteLine("[XUnitLogChecker]: Fixing the log failed.");
136+
WriteLineTimestamp("Fixing the log failed.");
138137
return FAILURE;
139138
}
140139

@@ -154,19 +153,22 @@ static int Main(string[] args)
154153
}
155154
else
156155
{
157-
Console.WriteLine("[XUnitLogChecker]: The provided dumps path"
158-
+ $" '{dumpsPath}' was not able to be read or"
159-
+ " found. Skipping stack traces search...");
156+
WriteLineTimestamp("The provided dumps path"
157+
+ $" '{dumpsPath}' was not able to be read or"
158+
+ " found. Skipping stack traces search...");
160159
}
161160
}
162161

163162
// Rename the temp log to the final log, so that Helix can use it without
164163
// knowing what transpired here.
165164
File.Move(tempLogPath, finalLogPath);
166-
Console.WriteLine("[XUnitLogChecker]: Finished!");
165+
WriteLineTimestamp("Finished!");
167166
return SUCCESS;
168167
}
169168

169+
static void WriteLineTimestamp(string message) =>
170+
Console.WriteLine($"[XUnitLogChecker]: {System.DateTime.Now:HH:mm:ss.ff}: {message}");
171+
170172
static IEnumerable<string> TryReadFile(string filePath)
171173
{
172174
// Declaring the enumerable to contain the log lines first because we
@@ -187,8 +189,8 @@ static IEnumerable<string> TryReadFile(string filePath)
187189
}
188190
catch (IOException ioEx)
189191
{
190-
Console.WriteLine("[XUnitLogChecker]: Could not read the"
191-
+ $" file {filePath}. Retrying...");
192+
WriteLineTimestamp("Could not read the"
193+
+ $" file {filePath}. Retrying...");
192194

193195
// Give it a couple seconds before trying again.
194196
Thread.Sleep(2000);
@@ -213,8 +215,8 @@ static bool FixTheXml(string xFile)
213215

214216
if (logLines is null)
215217
{
216-
Console.WriteLine("[XUnitLogChecker]: Timed out trying to read the"
217-
+ $" log file '{xFile}'.");
218+
WriteLineTimestamp("Timed out trying to read the"
219+
+ $" log file '{xFile}'.");
218220
return false;
219221
}
220222

@@ -303,7 +305,7 @@ static bool FixTheXml(string xFile)
303305

304306
if (tags.Count == 0)
305307
{
306-
Console.WriteLine($"[XUnitLogChecker]: XUnit log file '{xFile}' was A-OK!");
308+
WriteLineTimestamp($"XUnit log file '{xFile}' was A-OK!");
307309
return true;
308310
}
309311

@@ -318,7 +320,7 @@ static bool FixTheXml(string xFile)
318320
xsw.WriteLine($"</{tag}>");
319321
}
320322

321-
Console.WriteLine("[XUnitLogChecker]: XUnit log file has been fixed!");
323+
WriteLineTimestamp("XUnit log file has been fixed!");
322324
return true;
323325
}
324326

@@ -379,7 +381,7 @@ static TagResult[] GetOrderedTagMatches(Match[] openingTags, Match[] closingTags
379381

380382
static void PrintStackTracesFromDumps(string dumpsPath, string tempLogPath)
381383
{
382-
Console.WriteLine("[XUnitLogChecker]: Checking for dumps...");
384+
WriteLineTimestamp("Checking for dumps...");
383385

384386
// Read our newly fixed log to retrieve the time and date when the
385387
// test was run. This is to exclude potentially existing older dumps
@@ -401,17 +403,17 @@ static void PrintStackTracesFromDumps(string dumpsPath, string tempLogPath)
401403

402404
if (dumpsFound.Count() == 0)
403405
{
404-
Console.WriteLine("[XUnitLogChecker]: No crash dumps found. Continuing...");
406+
WriteLineTimestamp("No crash dumps found. Continuing...");
405407
return ;
406408
}
407409

408410
foreach (string dumpPath in dumpsFound)
409411
{
410412
if (OperatingSystem.IsWindows())
411413
{
412-
Console.WriteLine("[XUnitLogChecker]: Reading crash dump"
413-
+ $" '{dumpPath}'...");
414-
Console.WriteLine("[XUnitLogChecker]: Stack Trace Found:\n");
414+
WriteLineTimestamp("Reading crash dump"
415+
+ $" '{dumpPath}'...");
416+
WriteLineTimestamp("Stack Trace Found:\n");
415417

416418
CoreclrTestWrapperLib.TryPrintStackTraceFromDmp(dumpPath,
417419
Console.Out);
@@ -422,14 +424,14 @@ static void PrintStackTracesFromDumps(string dumpsPath, string tempLogPath)
422424

423425
if (!File.Exists(crashReportPath))
424426
{
425-
Console.WriteLine("[XUnitLogChecker]: There was no crash"
426-
+ $" report for dump '{dumpPath}'. Skipping...");
427+
WriteLineTimestamp("There was no crash"
428+
+ $" report for dump '{dumpPath}'. Skipping...");
427429
continue;
428430
}
429431

430-
Console.WriteLine("[XUnitLogChecker]: Reading crash report"
431-
+ $" '{crashReportPath}'...");
432-
Console.WriteLine("[XUnitLogChecker]: Stack Trace Found:\n");
432+
WriteLineTimestamp("Reading crash report"
433+
+ $" '{crashReportPath}'...");
434+
WriteLineTimestamp("Stack Trace Found:\n");
433435

434436
CoreclrTestWrapperLib.TryPrintStackTraceFromCrashReport(crashReportPath,
435437
Console.Out);

0 commit comments

Comments
 (0)