-
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
[17.12] Adding a static factory for the TerminalLogger #11016
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,6 +245,15 @@ internal TerminalLogger(ITerminal terminal) | |
_manualRefresh = true; | ||
} | ||
|
||
/// <summary> | ||
/// Private constructor invoked by static factory. | ||
/// </summary> | ||
private TerminalLogger(LoggerVerbosity verbosity, uint? originalConsoleMode) : this() | ||
{ | ||
Verbosity = verbosity; | ||
_originalConsoleMode = originalConsoleMode; | ||
} | ||
|
||
#region INodeLogger implementation | ||
|
||
/// <inheritdoc/> | ||
|
@@ -265,8 +274,6 @@ public void Initialize(IEventSource eventSource, int nodeCount) | |
/// <inheritdoc/> | ||
public void Initialize(IEventSource eventSource) | ||
{ | ||
(_, _, _originalConsoleMode) = NativeMethodsShared.QueryIsScreenAndTryEnableAnsiColorCodes(); | ||
|
||
ParseParameters(); | ||
|
||
eventSource.BuildStarted += BuildStarted; | ||
|
@@ -1050,6 +1057,24 @@ private void EraseNodes() | |
|
||
#region Helpers | ||
|
||
/// <summary> | ||
/// Creates a Terminal logger or Console logger based on the environment. | ||
/// This method is called by reflection from dotnet. Do not modify the name or parameters without adapting the SDK. | ||
/// </summary> | ||
public static ILogger CreateTerminalOrConsoleLogger(LoggerVerbosity verbosity) | ||
{ | ||
bool isDisabled = (Environment.GetEnvironmentVariable("MSBUILDTERMINALLOGGER") ?? string.Empty).Equals("off", StringComparison.InvariantCultureIgnoreCase); | ||
(bool supportsAnsi, bool outputIsScreen, uint? originalConsoleMode) = NativeMethodsShared.QueryIsScreenAndTryEnableAnsiColorCodes(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we can skip this if TL is requested to be disabled There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started with that intention, but this approach has lower complexity and the performance impact is negligible. |
||
|
||
if (isDisabled || !supportsAnsi || !outputIsScreen) | ||
{ | ||
NativeMethodsShared.RestoreConsoleMode(originalConsoleMode); | ||
return new ConsoleLogger(verbosity); | ||
} | ||
|
||
return new TerminalLogger(verbosity, originalConsoleMode); | ||
} | ||
|
||
/// <summary> | ||
/// Print a build result summary to the output. | ||
/// </summary> | ||
|
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.
One missing piece here is that while this does check the environment variable, the CLI flags (
--tl:off
, etc) are not respected. We may need a way to pass in an argv and have this method check for the presence/absence of the TL-related (and --console logger parameter!) flags to ensure uniform behavior.