-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Adding a static factory for the TerminalLogger #11318
base: main
Are you sure you want to change the base?
Conversation
…er instance based on settings and terminal capabilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
src/MSBuild/TerminalLogger/TerminalLogger.cs:1089
- [nitpick] The variable name 'tlArg' is ambiguous. It should be renamed to 'terminalLoggerArgument' for better readability.
string tlArg = args?.FirstOrDefault(a => a.StartsWith("--tl:", StringComparison.InvariantCultureIgnoreCase)) ?? string.Empty;
src/MSBuild/TerminalLogger/TerminalLogger.cs:1087
- Ensure that the new behavior introduced by the 'CreateTerminalOrConsoleLogger' method is covered by tests.
public static ILogger CreateTerminalOrConsoleLogger(LoggerVerbosity verbosity, string[]? args)
@baronfel, I know you would like to have full support for CLI logger configuration, but it will require some refactoring as the code for argument parsing is mostly placed in XMake. I wanted to break up XMake years ago, but now we have a valid reason to refactor at least part of the huge file :) If you don't mind, I would create a separate issue for this work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but should we use this factory in our own codebase to dogfood?
Yeah, that is quite a large unit of work - makes sense to carve it out. |
I wanted to do it from the beginning, but the entry point logic emits global messages when it detects that TL couldn't be used. The easiest solution is to make the list of deferred messages in I think we could move the factory to some already public type like Edit: I'm looking at |
We decided to reuse parameters parsing logic to support all CL and TL logger parameters in this case. |
We agreed to use the factory as is and make it public. Support for all parameters will be added later. |
a.StartsWith("/tl:", StringComparison.InvariantCultureIgnoreCase) || | ||
a.StartsWith("-tl:", StringComparison.InvariantCultureIgnoreCase) || | ||
a.StartsWith("--tl:", StringComparison.InvariantCultureIgnoreCase)) ?? string.Empty; | ||
|
||
bool isDisabled = | ||
tlArg.EndsWith("tl:on", StringComparison.InvariantCultureIgnoreCase) ? false : | ||
tlArg.EndsWith("tl:off", StringComparison.InvariantCultureIgnoreCase) ? true : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to support the long form too, which makes this complex enough that I lean to "screw it use a regex"
(?:/|-|--)(?:tl|terminallogger):(?'value'on|off)
@@ -136,7 +136,6 @@ | |||
<Compile Include="CommandLineSwitchException.cs" /> | |||
<Compile Include="..\Shared\CoreCLRAssemblyLoader.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'" /> | |||
<Compile Include="DistributedLoggerRecord.cs" /> | |||
<Compile Include="TerminalLogger\*.cs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why un-glob?
@@ -396,7 +403,7 @@ private void BuildStarted(object sender, BuildStartedEventArgs e) | |||
|
|||
_buildStartTime = e.Timestamp; | |||
|
|||
if (Terminal.SupportsProgressReporting) | |||
if (Terminal.SupportsProgressReporting && Verbosity != LoggerVerbosity.Quiet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I see why "quiet" implies "don't make the spinner go", can you elaborate on that a bit?
[InlineData("-tl:on", true, true, "off", "TerminalLogger")] | ||
public void CreateTerminalOrConsoleLogger_CreatesCorrectLoggerInstance(string argsString, bool supportsAnsi, bool outputIsScreen, string evnVariableValue, string expectedLoggerName) | ||
{ | ||
string originalValue = Environment.GetEnvironmentVariable("MSBUILDTERMINALLOGGER"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestEnvironment
has helpers for this, can you switch to them?
/// </summary> | ||
/// <param name="verbosity">Level of detail to show in the log.</param> | ||
/// <param name="args">Command line arguments for the logger configuration. Currently, only '--tl:off' and '--tl:on' are supported right now.</param> | ||
public static ILogger CreateTerminalOrConsoleLogger(LoggerVerbosity verbosity, string[] args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is surprising to me that we're not extracting the verbosity from the command line too. Should we?
Fixes #10998
Context
Although I created the SDK hotfix to always use the
ConsoleLogger
, we want to useTerminalLogger
when it's possible.Changes Made
Added a static factory that can return instance of Terminal or Console logger based on current environment. The usage of TerminalLogger in this scenario can be explicitly disabled by using of already existing env. variable or CLI argument
--tl:off
.This change also prevents emitting of progress indication when the verbosity is set to
quiet
.Notes
I tried to move TL to
Microsoft.Build
, where it belongs, but we don't want to make it public. Unfortunately, using theInternalsVisibleTo
attribute to expose this type to theMSBuild
project causes many type conflicts due to shared sources. Using the reflection is an ugly, but unnecessary workaround to make the factory public :(