Skip to content

Commit

Permalink
Add diag log env variable (#3275)
Browse files Browse the repository at this point in the history
* Add diag log env variable

* Rename and use verbosity

* Fix parameter name

* Apply suggestions from code review

Co-authored-by: Amaury Levé <[email protected]>

* Add comments about values

Co-authored-by: Amaury Levé <[email protected]>
  • Loading branch information
nohwnd and Evangelink authored Jan 25, 2022
1 parent e51ef45 commit 5e94a38
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/vstest.console/CommandLine/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ internal int Execute(params string[] args)
{
this.testPlatformEventSource.VsTestConsoleStart();

var isDiag = args != null && args.Any(arg => arg.StartsWith("--diag", StringComparison.OrdinalIgnoreCase));

// If User specifies --nologo via dotnet, do not print splat screen
if (args != null && args.Length !=0 && args.Contains("--nologo"))
{
Expand All @@ -100,7 +102,6 @@ internal int Execute(params string[] args)
}
else
{
var isDiag = args != null && args.Any(arg => arg.StartsWith("--diag", StringComparison.OrdinalIgnoreCase));
this.PrintSplashScreen(isDiag);
}

Expand All @@ -114,6 +115,27 @@ internal int Execute(params string[] args)
exitCode = 1;
}

if (!isDiag)
{
// This takes a path to log directory and log.txt file. Same as the --diag parameter, e.g. VSTEST_DIAG="logs\log.txt"
var diag = Environment.GetEnvironmentVariable("VSTEST_DIAG");
// This takes Verbose, Info (not Information), Warning, and Error.
var diagVerbosity = Environment.GetEnvironmentVariable("VSTEST_DIAG_VERBOSITY");
if (!string.IsNullOrWhiteSpace(diag))
{
var verbosity = TraceLevel.Verbose;
if (diagVerbosity != null)
{
if (Enum.TryParse<TraceLevel>(diagVerbosity, ignoreCase: true, out var parsedVerbosity))
{
verbosity = parsedVerbosity;
}
}

args = args.Concat(new[] { $"--diag:{diag};TraceLevel={verbosity}" }).ToArray();
}
}

// Flatten arguments and process response files.
string[] flattenedArguments;
exitCode |= this.FlattenArguments(args, out flattenedArguments);
Expand Down

0 comments on commit 5e94a38

Please sign in to comment.