Skip to content

Commit c09528f

Browse files
authored
Make Terminal Logger respect verbosity (#9810)
Fixes #9667, #9654 Context We would like to make the terminal logger partially respect verbosity. Changes Made In case of Quiet verbosity, none of the static part of the Terminal Logger output, which is grouped by the project, is shown. Warnings and errors are shown as they come immediately. In case of Minimal and Normal verbosity, the behavior stands intact. In case of Detailed and Diagnostic verbosity, the terminal logger shows all the high priority messages in the static part of the output, under the corresponding project. Testing Locally & unit tests
1 parent 08e84a9 commit c09528f

File tree

38 files changed

+645
-123
lines changed

38 files changed

+645
-123
lines changed

src/Build/Logging/BaseConsoleLogger.cs

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Threading;
1313
using Microsoft.Build.Evaluation;
1414
using Microsoft.Build.Framework;
15+
using Microsoft.Build.Framework.Logging;
1516
using Microsoft.Build.Internal;
1617
using Microsoft.Build.Shared;
1718
using ColorResetter = Microsoft.Build.Logging.ColorResetter;
@@ -75,20 +76,9 @@ internal abstract class BaseConsoleLogger : INodeLogger, IStringBuilderProvider
7576
/// </summary>
7677
public void ParseParameters()
7778
{
78-
if (Parameters == null)
79+
foreach (var parameter in LoggerParametersHelper.ParseParameters(Parameters))
7980
{
80-
return;
81-
}
82-
83-
foreach (string parameter in Parameters.Split(parameterDelimiters))
84-
{
85-
if (string.IsNullOrWhiteSpace(parameter))
86-
{
87-
continue;
88-
}
89-
90-
string[] parameterAndValue = parameter.Split(s_parameterValueSplitCharacter);
91-
ApplyParameter(parameterAndValue[0], parameterAndValue.Length > 1 ? parameterAndValue[1] : null);
81+
ApplyParameter(parameter.Item1, parameter.Item2);
9282
}
9383
}
9484

@@ -1038,33 +1028,17 @@ internal virtual bool ApplyParameter(string parameterName, string parameterValue
10381028
/// </summary>
10391029
private bool ApplyVerbosityParameter(string parameterValue)
10401030
{
1041-
switch (parameterValue.ToUpperInvariant())
1031+
if (LoggerParametersHelper.TryParseVerbosityParameter(parameterValue, out LoggerVerbosity? verbosity))
10421032
{
1043-
case "Q":
1044-
case "QUIET":
1045-
Verbosity = LoggerVerbosity.Quiet;
1046-
return true;
1047-
case "M":
1048-
case "MINIMAL":
1049-
Verbosity = LoggerVerbosity.Minimal;
1050-
return true;
1051-
case "N":
1052-
case "NORMAL":
1053-
Verbosity = LoggerVerbosity.Normal;
1054-
return true;
1055-
case "D":
1056-
case "DETAILED":
1057-
Verbosity = LoggerVerbosity.Detailed;
1058-
return true;
1059-
case "DIAG":
1060-
case "DIAGNOSTIC":
1061-
Verbosity = LoggerVerbosity.Diagnostic;
1062-
return true;
1063-
default:
1064-
string errorCode;
1065-
string helpKeyword;
1066-
string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out errorCode, out helpKeyword, "InvalidVerbosity", parameterValue);
1067-
throw new LoggerException(message, null, errorCode, helpKeyword);
1033+
Verbosity = (LoggerVerbosity)verbosity;
1034+
return true;
1035+
}
1036+
else
1037+
{
1038+
string errorCode;
1039+
string helpKeyword;
1040+
string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out errorCode, out helpKeyword, "InvalidVerbosity", parameterValue);
1041+
throw new LoggerException(message, null, errorCode, helpKeyword);
10681042
}
10691043
}
10701044

@@ -1135,16 +1109,6 @@ private bool ApplyVerbosityParameter(string parameterValue)
11351109
internal const string projectSeparatorLine =
11361110
"__________________________________________________";
11371111

1138-
/// <summary>
1139-
/// Console logger parameters delimiters.
1140-
/// </summary>
1141-
internal static readonly char[] parameterDelimiters = MSBuildConstants.SemicolonChar;
1142-
1143-
/// <summary>
1144-
/// Console logger parameter value split character.
1145-
/// </summary>
1146-
private static readonly char[] s_parameterValueSplitCharacter = MSBuildConstants.EqualsChar;
1147-
11481112
/// <summary>
11491113
/// When true, accumulate performance numbers.
11501114
/// </summary>

src/Build/Logging/ConsoleLogger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using Microsoft.Build.BackEnd.Logging;
66
using Microsoft.Build.Framework;
7+
using Microsoft.Build.Framework.Logging;
78
using Microsoft.Build.Framework.Telemetry;
89
using Microsoft.Build.Shared;
910
using BaseConsoleLogger = Microsoft.Build.BackEnd.Logging.BaseConsoleLogger;
@@ -113,7 +114,7 @@ private void InitializeBaseConsoleLogger()
113114
bool preferConsoleColor = false;
114115
if (!string.IsNullOrEmpty(_parameters))
115116
{
116-
string[] parameterComponents = _parameters.Split(BaseConsoleLogger.parameterDelimiters);
117+
string[] parameterComponents = _parameters.Split(LoggerParametersHelper.s_parameterDelimiters);
117118
foreach (string param in parameterComponents)
118119
{
119120
if (param.Length <= 0)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Microsoft.Build.Shared;
11+
12+
namespace Microsoft.Build.Framework.Logging
13+
{
14+
internal static class LoggerParametersHelper
15+
{
16+
// Logger parameters delimiters.
17+
public static readonly char[] s_parameterDelimiters = MSBuildConstants.SemicolonChar;
18+
19+
// Logger parameter value split character.
20+
public static readonly char[] s_parameterValueSplitCharacter = MSBuildConstants.EqualsChar;
21+
22+
public static bool TryParseVerbosityParameter(string parameterValue, [NotNullWhen(true)] out LoggerVerbosity? verbosity)
23+
{
24+
switch (parameterValue.ToUpperInvariant())
25+
{
26+
case "Q":
27+
case "QUIET":
28+
verbosity = LoggerVerbosity.Quiet;
29+
return true;
30+
case "M":
31+
case "MINIMAL":
32+
verbosity = LoggerVerbosity.Minimal;
33+
return true;
34+
case "N":
35+
case "NORMAL":
36+
verbosity = LoggerVerbosity.Normal;
37+
return true;
38+
case "D":
39+
case "DETAILED":
40+
verbosity = LoggerVerbosity.Detailed;
41+
return true;
42+
case "DIAG":
43+
case "DIAGNOSTIC":
44+
verbosity = LoggerVerbosity.Diagnostic;
45+
return true;
46+
default:
47+
verbosity = null;
48+
return false;
49+
}
50+
}
51+
52+
public static IEnumerable<Tuple<string, string?>> ParseParameters(string? parametersString)
53+
{
54+
if (parametersString is not null)
55+
{
56+
foreach (string parameter in parametersString.Split(s_parameterDelimiters))
57+
{
58+
if (string.IsNullOrWhiteSpace(parameter))
59+
{
60+
continue;
61+
}
62+
63+
string[] parameterAndValue = parameter.Split(s_parameterValueSplitCharacter);
64+
yield return new Tuple<string, string?>(parameterAndValue[0], parameterAndValue.Length > 1 ? parameterAndValue[1] : null);
65+
}
66+
}
67+
}
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
]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`
2+
project failed with 1 error(s) and 1 warning(s) (0.2s)
3+
High importance message!
4+
directory/file(1,2,3,4): warning AA0000: Warning!
5+
directory/file(1,2,3,4): error AA0000: Error!
6+
[?25l
7+
[?25h
8+
Build failed with 1 error(s) and 1 warning(s) in 5.0s
9+
]9;4;0;\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
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`
2+
project failed with 1 error(s) and 1 warning(s) (0.2s)
3+
High importance message!
4+
directory/file(1,2,3,4): warning AA0000: Warning!
5+
directory/file(1,2,3,4): error AA0000: Error!
6+
[?25l
7+
[?25h
8+
Build failed with 1 error(s) and 1 warning(s) in 5.0s
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
]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`
2+
project failed with 1 error(s) and 1 warning(s) (0.2s)
3+
High importance message!
4+
directory/file(1,2,3,4): warning AA0000: Warning!
5+
directory/file(1,2,3,4): error AA0000: Error!
6+
[?25l
7+
[?25h
8+
Build failed with 1 error(s) and 1 warning(s) in 5.0s
9+
]9;4;0;\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
]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`
2+
project failed with 1 error(s) and 1 warning(s) (0.2s)
3+
High importance message!
4+
directory/file(1,2,3,4): warning AA0000: Warning!
5+
directory/file(1,2,3,4): error AA0000: Error!
6+
[?25l
7+
[?25h
8+
Build failed with 1 error(s) and 1 warning(s) in 5.0s
9+
]9;4;0;\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
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`
2+
project failed with 1 error(s) and 1 warning(s) (0.2s)
3+
High importance message!
4+
directory/file(1,2,3,4): warning AA0000: Warning!
5+
directory/file(1,2,3,4): error AA0000: Error!
6+
[?25l
7+
[?25h
8+
Build failed with 1 error(s) and 1 warning(s) in 5.0s
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
]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`
2+
project failed with 1 error(s) and 1 warning(s) (0.2s)
3+
High importance message!
4+
directory/file(1,2,3,4): warning AA0000: Warning!
5+
directory/file(1,2,3,4): error AA0000: Error!
6+
[?25l
7+
[?25h
8+
Build failed with 1 error(s) and 1 warning(s) in 5.0s
9+
]9;4;0;\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
]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`
2+
project failed with 1 error(s) and 1 warning(s) (0.2s)
3+
directory/file(1,2,3,4): warning AA0000: Warning!
4+
directory/file(1,2,3,4): error AA0000: Error!
5+
[?25l
6+
[?25h
7+
Build failed with 1 error(s) and 1 warning(s) in 5.0s
8+
]9;4;0;\

0 commit comments

Comments
 (0)