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

TL: Fix logs appearance from nuget client/credential provider #9407

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MSBuild/TerminalLogger/MessageSeverity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ namespace Microsoft.Build.Logging.TerminalLogger;
/// <summary>
/// Enumerates the supported message severities.
/// </summary>
internal enum MessageSeverity { Warning, Error, Blocking }
internal enum MessageSeverity { Warning, Error }
42 changes: 24 additions & 18 deletions src/MSBuild/TerminalLogger/TerminalLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
Expand All @@ -26,7 +27,8 @@ namespace Microsoft.Build.Logging.TerminalLogger;
internal sealed class TerminalLogger : INodeLogger
{
private const string FilePathPattern = " -> ";
private readonly string[] _immediateMessageMarkers = new[] { "[CredentialProvider]", "--interactive" };
private const char PatternSeparator = '|';
private readonly string _immediateMessagePattern = $"[CredentialProvider]{PatternSeparator}--interactive";

/// <summary>
/// A wrapper over the project context ID passed to us in <see cref="IEventSource"/> logger events.
Expand Down Expand Up @@ -565,10 +567,9 @@ private void MessageRaised(object sender, BuildMessageEventArgs e)
}
}

// Detect markers that require special attention from a customer.
if (_immediateMessageMarkers.Any(marker => message.IndexOf(marker, StringComparison.Ordinal) > 0))
if (ImmeidateMessageRaised(message))
{
RenderImmediateMessage(message, MessageSeverity.Blocking);
RenderImmediateMessage(message);
}
}
}
Expand All @@ -595,15 +596,27 @@ private void WarningRaised(object sender, BuildWarningEventArgs e)
threadId: e.ThreadId,
logOutputProperties: null);

if (_immediateMessageMarkers.Any(marker => message.IndexOf(marker, StringComparison.Ordinal) > 0))
if (ImmeidateMessageRaised(message))
{
RenderImmediateMessage(message, MessageSeverity.Warning);
RenderImmediateMessage(message);
}

project.AddBuildMessage(MessageSeverity.Warning, message);
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// <summary>
/// Detectw markers that require special attention from a customer.
/// </summary>
/// <param name="message">Raised event</param>
/// <returns>true if marker is detected.</returns>
private bool ImmeidateMessageRaised(string message)
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved
{
Regex regex = new Regex($"({_immediateMessagePattern})");
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved

return regex.IsMatch(message);
}

/// <summary>
/// The <see cref="IEventSource.ErrorRaised"/> callback.
/// </summary>
Expand Down Expand Up @@ -867,19 +880,12 @@ private string RenderBuildResult(bool succeeded, bool hasError, bool hasWarning)
/// </summary>
/// <param name="message">Build message needed to be shown immediately.</param>
/// <param name="severity">Message severity.</param>
private void RenderImmediateMessage(string message, MessageSeverity severity)
private void RenderImmediateMessage(string message)
{
string styledMessage = severity switch
{
MessageSeverity.Warning => AnsiCodes.Colorize(message, TerminalColor.Yellow),
MessageSeverity.Blocking => AnsiCodes.Colorize(message, TerminalColor.Blue),
_ => string.Empty,
};

if (!string.IsNullOrEmpty(styledMessage))
{
Terminal.WriteLine(styledMessage);
}
// Calling erase helps to clear the screen before printing the message
// The immediate output will not overlap with node status reporting
EraseNodes();
Terminal.WriteLine(message);
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down
Loading