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

Make Terminal Logger respect verbosity #9810

Merged
merged 15 commits into from
Apr 3, 2024
62 changes: 13 additions & 49 deletions src/Build/Logging/BaseConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Threading;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Logging;
using Microsoft.Build.Internal;
using Microsoft.Build.Shared;
using ColorResetter = Microsoft.Build.Logging.ColorResetter;
Expand Down Expand Up @@ -75,20 +76,9 @@ internal abstract class BaseConsoleLogger : INodeLogger, IStringBuilderProvider
/// </summary>
public void ParseParameters()
{
if (Parameters == null)
foreach (var parameter in LoggerParametersHelper.ParseParameters(Parameters))
{
return;
}

foreach (string parameter in Parameters.Split(parameterDelimiters))
{
if (string.IsNullOrWhiteSpace(parameter))
{
continue;
}

string[] parameterAndValue = parameter.Split(s_parameterValueSplitCharacter);
ApplyParameter(parameterAndValue[0], parameterAndValue.Length > 1 ? parameterAndValue[1] : null);
ApplyParameter(parameter.Item1, parameter.Item2);
}
}

Expand Down Expand Up @@ -1038,33 +1028,17 @@ internal virtual bool ApplyParameter(string parameterName, string parameterValue
/// </summary>
private bool ApplyVerbosityParameter(string parameterValue)
{
switch (parameterValue.ToUpperInvariant())
if (LoggerParametersHelper.TryParseVerbosityParameter(parameterValue, out LoggerVerbosity? verbosity))
{
case "Q":
case "QUIET":
Verbosity = LoggerVerbosity.Quiet;
return true;
case "M":
case "MINIMAL":
Verbosity = LoggerVerbosity.Minimal;
return true;
case "N":
case "NORMAL":
Verbosity = LoggerVerbosity.Normal;
return true;
case "D":
case "DETAILED":
Verbosity = LoggerVerbosity.Detailed;
return true;
case "DIAG":
case "DIAGNOSTIC":
Verbosity = LoggerVerbosity.Diagnostic;
return true;
default:
string errorCode;
string helpKeyword;
string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out errorCode, out helpKeyword, "InvalidVerbosity", parameterValue);
throw new LoggerException(message, null, errorCode, helpKeyword);
Verbosity = (LoggerVerbosity)verbosity;
return true;
}
else
{
string errorCode;
string helpKeyword;
string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out errorCode, out helpKeyword, "InvalidVerbosity", parameterValue);
throw new LoggerException(message, null, errorCode, helpKeyword);
}
}

Expand Down Expand Up @@ -1135,16 +1109,6 @@ private bool ApplyVerbosityParameter(string parameterValue)
internal const string projectSeparatorLine =
"__________________________________________________";

/// <summary>
/// Console logger parameters delimiters.
/// </summary>
internal static readonly char[] parameterDelimiters = MSBuildConstants.SemicolonChar;

/// <summary>
/// Console logger parameter value split character.
/// </summary>
private static readonly char[] s_parameterValueSplitCharacter = MSBuildConstants.EqualsChar;

/// <summary>
/// When true, accumulate performance numbers.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Build/Logging/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Logging;
using Microsoft.Build.Framework.Telemetry;
using Microsoft.Build.Shared;
using BaseConsoleLogger = Microsoft.Build.BackEnd.Logging.BaseConsoleLogger;
Expand Down Expand Up @@ -113,7 +114,7 @@ private void InitializeBaseConsoleLogger()
bool preferConsoleColor = false;
if (!string.IsNullOrEmpty(_parameters))
{
string[] parameterComponents = _parameters.Split(BaseConsoleLogger.parameterDelimiters);
string[] parameterComponents = _parameters.Split(LoggerParametersHelper.s_parameterDelimiters);
foreach (string param in parameterComponents)
{
if (param.Length <= 0)
Expand Down
69 changes: 69 additions & 0 deletions src/Framework/Logging/LoggerParametersHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.Shared;

namespace Microsoft.Build.Framework.Logging
{
internal static class LoggerParametersHelper
{
// Logger parameters delimiters.
public static readonly char[] s_parameterDelimiters = MSBuildConstants.SemicolonChar;

// Logger parameter value split character.
public static readonly char[] s_parameterValueSplitCharacter = MSBuildConstants.EqualsChar;

public static bool TryParseVerbosityParameter(string parameterValue, [NotNullWhen(true)] out LoggerVerbosity? verbosity)
{
switch (parameterValue.ToUpperInvariant())
{
case "Q":
case "QUIET":
verbosity = LoggerVerbosity.Quiet;
return true;
case "M":
case "MINIMAL":
verbosity = LoggerVerbosity.Minimal;
return true;
case "N":
case "NORMAL":
verbosity = LoggerVerbosity.Normal;
return true;
case "D":
case "DETAILED":
verbosity = LoggerVerbosity.Detailed;
return true;
case "DIAG":
case "DIAGNOSTIC":
verbosity = LoggerVerbosity.Diagnostic;
return true;
default:
verbosity = null;
return false;
}
}

public static IEnumerable<Tuple<string, string?>> ParseParameters(string? parametersString)
{
if (parametersString is not null)
{
foreach (string parameter in parametersString.Split(s_parameterDelimiters))
{
if (string.IsNullOrWhiteSpace(parameter))
{
continue;
}

string[] parameterAndValue = parameter.Split(s_parameterValueSplitCharacter);
yield return new Tuple<string, string?>(parameterAndValue[0], parameterAndValue.Length > 1 ? parameterAndValue[1] : null);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
High importance message!
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
High importance message!
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
High importance message!
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
High importance message!
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
High importance message!
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
High importance message!
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
]9;4;3;\directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
]9;4;3;\directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
High importance message!
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
High importance message!
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
]9;4;3;\The plugin credential provider could not acquire credentials.Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
project failed with 1 error(s) and 1 warning(s) (0.2s)
High importance message!
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
]9;4;3;\ project succeeded (0.2s)
Task Command Line.
[?25l
[?25h
Build succeeded in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
 project succeeded (0.2s)
Task Command Line.
[?25l
[?25h
Build succeeded in 5.0s
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
]9;4;3;\ project succeeded (0.2s)
Task Command Line.
[?25l
[?25h
Build succeeded in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
]9;4;3;\[?25l
[?25h
Build succeeded in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[?25l
[?25h
Build succeeded in 5.0s
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
]9;4;3;\[?25l
[?25h
Build succeeded in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
]9;4;3;\ project test succeeded (0.2s)
[?25l
[?25h
Build succeeded in 5.0s
Test run failed. Total: 10 Failed: 1 Passed: 7 Skipped: 2, Duration: 1.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
 project test succeeded (0.2s)
[?25l
[?25h
Build succeeded in 5.0s
Test run failed. Total: 10 Failed: 1 Passed: 7 Skipped: 2, Duration: 1.0s
Loading