-
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. |
@@ -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?
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.
Requested by @baronfel
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.
Exactly - users think of --quiet
as --silent
in other tools - meaning there should be no observable change at all if possible. In lieu of another explicit "don't do progress/spinners/etc" flag that should disable the spinner because it mangles the output.
bool isDisabled = | ||
tlArg.Equals("on", StringComparison.InvariantCultureIgnoreCase) ? false : | ||
tlArg.Equals("off", StringComparison.InvariantCultureIgnoreCase) ? true : | ||
(Environment.GetEnvironmentVariable("MSBUILDTERMINALLOGGER") ?? string.Empty).Equals("off", StringComparison.InvariantCultureIgnoreCase); |
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.
this is different than creating Terminal logger in Xmake 😩 - there it recognizes "false" and "0" as well. (it's a bit silly part of Xmake)
Line 2966 in 072c659
string NormalizeIntoBooleanValues() |
Also could this code live in Traits?
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 probably blind, but the NormalizeIntoBooleanValues()
is testing the variable for on
and off
values :)
I want to use Traits eventually, but there is a set of tasks that I want to resolve first.
- We need to place all our resources to single assembly
- Then we can get rid of shared sources from MSBuild and use InternalsVisibleTo without type conflicts
- Then we can move the CommandLineSwitches* to Microsoft.Build
- Then we can move the arg parsing logic from XMake to this project and invoke the factory from XMake
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.
oops I meant to link the whole method processing tl args
Line 2826 in 072c659
private static bool ProcessTerminalLoggerConfiguration(CommandLineSwitches commandLineSwitches, out string aggregatedParameters) |
the logic is basically:
- try getting -tl: value from console or from the env var
- convert "on" to "true", "off" to "false"
- parse a boolean from a string -> the actual info whether to use terminal logger
(at this point I am confused what it'll do for 0 and 1, but for true and false it'll definitely set the tl on or off)
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
.