Skip to content

Commit

Permalink
Merge pull request #8356 from edvilme/edvilme-flg-llg
Browse files Browse the repository at this point in the history
[FancyLogger] -> LiveLogger
  • Loading branch information
MichalPavlik authored Feb 1, 2023
2 parents 7bf5113 + fa10283 commit 7cfb36c
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 149 deletions.
21 changes: 0 additions & 21 deletions documentation/fancylogger/Opt-In-Mechanism.md

This file was deleted.

19 changes: 19 additions & 0 deletions documentation/livelogger/Opt-In-Mechanism.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# When should we use LiveLogger

The LiveLogger presents the user with the build's most relevant information at the time, automatically hiding all the information that is no longer relevant (as to prevent huge log outputs). However, many users might find this not very useful (or even counterproductive) such as those using a terminal without proper ANSI support or when redirecting the output to a file. For that reason, the users must be able to turn this feature on/off at will.

# Proposal
Using the `/livelogger` or `/ll` command line switches, users are able to opt-in and use the LiveLogger, EXCEPT when:
- The terminal does not support ANSI codes or color
- Output is redirected to a file or pipe

For early development stages, an environment variable `$MSBUILDLIVELOGGER` should be enabled to prevent accidental access to an unfinished feature.

In cases where the LiveLogger should not be enabled, the default ConsoleLogger should be used instead.

# Considerations
## Should LiveLogger be used with other loggers (eg, BinaryLogger, FileLogger, custom loggers)?
LiveLogger should only replace the current ConsoleLogger for the aforementioned cases. Additionally, other loggers can be used in conjunction.

## Should output be ignored with the `/noconsolelogger` flag enabled?
LiveLogger serves as a replacement for ConsoleLogger, so it should behave similarly. When attaching the `/noconsolelogger` flag, it should not output anything.
38 changes: 19 additions & 19 deletions src/MSBuild/CommandLineSwitches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal enum ParameterlessSwitch
FileLogger8,
FileLogger9,
DistributedFileLogger,
FancyLogger,
LiveLogger,
#if DEBUG
WaitForDebugger,
#endif
Expand Down Expand Up @@ -201,25 +201,25 @@ internal ParameterizedSwitchInfo(
//---------------------------------------------------------------------------------------------------------------------------------------------------
// Switch Names Switch Id Dup Error Light up key
//---------------------------------------------------------------------------------------------------------------------------------------------------
new ParameterlessSwitchInfo( new string[] { "help", "h", "?" }, ParameterlessSwitch.Help, null),
new ParameterlessSwitchInfo( new string[] { "version", "ver" }, ParameterlessSwitch.Version, null),
new ParameterlessSwitchInfo( new string[] { "nologo" }, ParameterlessSwitch.NoLogo, null),
new ParameterlessSwitchInfo( new string[] { "noautoresponse", "noautorsp" }, ParameterlessSwitch.NoAutoResponse, null),
new ParameterlessSwitchInfo( new string[] { "noconsolelogger", "noconlog" }, ParameterlessSwitch.NoConsoleLogger, null),
new ParameterlessSwitchInfo( new string[] { "filelogger", "fl" }, ParameterlessSwitch.FileLogger, null),
new ParameterlessSwitchInfo( new string[] { "filelogger1", "fl1" }, ParameterlessSwitch.FileLogger1, null),
new ParameterlessSwitchInfo( new string[] { "filelogger2", "fl2" }, ParameterlessSwitch.FileLogger2, null),
new ParameterlessSwitchInfo( new string[] { "filelogger3", "fl3" }, ParameterlessSwitch.FileLogger3, null),
new ParameterlessSwitchInfo( new string[] { "filelogger4", "fl4" }, ParameterlessSwitch.FileLogger4, null),
new ParameterlessSwitchInfo( new string[] { "filelogger5", "fl5" }, ParameterlessSwitch.FileLogger5, null),
new ParameterlessSwitchInfo( new string[] { "filelogger6", "fl6" }, ParameterlessSwitch.FileLogger6, null),
new ParameterlessSwitchInfo( new string[] { "filelogger7", "fl7" }, ParameterlessSwitch.FileLogger7, null),
new ParameterlessSwitchInfo( new string[] { "filelogger8", "fl8" }, ParameterlessSwitch.FileLogger8, null),
new ParameterlessSwitchInfo( new string[] { "filelogger9", "fl9" }, ParameterlessSwitch.FileLogger9, null),
new ParameterlessSwitchInfo( new string[] { "distributedfilelogger", "dfl" }, ParameterlessSwitch.DistributedFileLogger, null),
new ParameterlessSwitchInfo( new string[] { "fancylogger", "flg" }, ParameterlessSwitch.FancyLogger, null),
new ParameterlessSwitchInfo( new string[] { "help", "h", "?" }, ParameterlessSwitch.Help, null),
new ParameterlessSwitchInfo( new string[] { "version", "ver" }, ParameterlessSwitch.Version, null),
new ParameterlessSwitchInfo( new string[] { "nologo" }, ParameterlessSwitch.NoLogo, null),
new ParameterlessSwitchInfo( new string[] { "noautoresponse", "noautorsp" }, ParameterlessSwitch.NoAutoResponse, null),
new ParameterlessSwitchInfo( new string[] { "noconsolelogger", "noconlog" }, ParameterlessSwitch.NoConsoleLogger, null),
new ParameterlessSwitchInfo( new string[] { "filelogger", "fl" }, ParameterlessSwitch.FileLogger, null),
new ParameterlessSwitchInfo( new string[] { "filelogger1", "fl1" }, ParameterlessSwitch.FileLogger1, null),
new ParameterlessSwitchInfo( new string[] { "filelogger2", "fl2" }, ParameterlessSwitch.FileLogger2, null),
new ParameterlessSwitchInfo( new string[] { "filelogger3", "fl3" }, ParameterlessSwitch.FileLogger3, null),
new ParameterlessSwitchInfo( new string[] { "filelogger4", "fl4" }, ParameterlessSwitch.FileLogger4, null),
new ParameterlessSwitchInfo( new string[] { "filelogger5", "fl5" }, ParameterlessSwitch.FileLogger5, null),
new ParameterlessSwitchInfo( new string[] { "filelogger6", "fl6" }, ParameterlessSwitch.FileLogger6, null),
new ParameterlessSwitchInfo( new string[] { "filelogger7", "fl7" }, ParameterlessSwitch.FileLogger7, null),
new ParameterlessSwitchInfo( new string[] { "filelogger8", "fl8" }, ParameterlessSwitch.FileLogger8, null),
new ParameterlessSwitchInfo( new string[] { "filelogger9", "fl9" }, ParameterlessSwitch.FileLogger9, null),
new ParameterlessSwitchInfo( new string[] { "distributedfilelogger", "dfl" }, ParameterlessSwitch.DistributedFileLogger, null),
new ParameterlessSwitchInfo( new string[] { "livelogger", "ll", "fancylogger", "flg" }, ParameterlessSwitch.LiveLogger, null),
#if DEBUG
new ParameterlessSwitchInfo( new string[] { "waitfordebugger", "wfd" }, ParameterlessSwitch.WaitForDebugger, null),
new ParameterlessSwitchInfo( new string[] { "waitfordebugger", "wfd" }, ParameterlessSwitch.WaitForDebugger, null),
#endif
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Microsoft.Build.Logging.FancyLogger
namespace Microsoft.Build.Logging.LiveLogger
{
internal static class ANSIBuilder
{
public static string ANSIRegex = @"\x1b(?:[@-Z\-_]|\[[0-?]*[ -\/]*[@-~])";
// TODO: This should replace ANSIRegex once FancyLogger's API is internal
// TODO: This should replace ANSIRegex once LiveLogger's API is internal
public static Regex ANSIRegexRegex = new Regex(ANSIRegex);
public static string ANSIRemove(string text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
using System.Threading.Tasks;
using Microsoft.Build.Framework;

namespace Microsoft.Build.Logging.FancyLogger
namespace Microsoft.Build.Logging.LiveLogger
{
internal class FancyLogger : ILogger
internal class LiveLogger : ILogger
{
private Dictionary<int, FancyLoggerProjectNode> projects = new Dictionary<int, FancyLoggerProjectNode>();
private Dictionary<int, ProjectNode> projects = new Dictionary<int, ProjectNode>();

private bool Succeeded;

Expand All @@ -21,7 +21,7 @@ internal class FancyLogger : ILogger

public LoggerVerbosity Verbosity { get; set; }

public FancyLogger()
public LiveLogger()
{
Parameters = "";
}
Expand Down Expand Up @@ -54,15 +54,15 @@ public void Initialize(IEventSource eventSource)

private void Render()
{
// Initialize FancyLoggerBuffer
FancyLoggerBuffer.Initialize();
// Initialize LiveLoggerBuffer
TerminalBuffer.Initialize();
// TODO: Fix. First line does not appear at top. Leaving empty line for now
FancyLoggerBuffer.WriteNewLine(string.Empty);
TerminalBuffer.WriteNewLine(string.Empty);
// First render
FancyLoggerBuffer.Render();
TerminalBuffer.Render();
int i = 0;
// Rerender periodically
while (!FancyLoggerBuffer.IsTerminated)
while (!TerminalBuffer.IsTerminated)
{
i++;
// Delay by 1/60 seconds
Expand All @@ -75,7 +75,7 @@ private void Render()
project.Value.Log();
}
// Rerender buffer
FancyLoggerBuffer.Render();
TerminalBuffer.Render();
});
// Handle keyboard input
if (Console.KeyAvailable)
Expand All @@ -84,15 +84,15 @@ private void Render()
switch (key)
{
case ConsoleKey.UpArrow:
if (FancyLoggerBuffer.TopLineIndex > 0)
if (TerminalBuffer.TopLineIndex > 0)
{
FancyLoggerBuffer.TopLineIndex--;
TerminalBuffer.TopLineIndex--;
}
FancyLoggerBuffer.ShouldRerender = true;
TerminalBuffer.ShouldRerender = true;
break;
case ConsoleKey.DownArrow:
FancyLoggerBuffer.TopLineIndex++;
FancyLoggerBuffer.ShouldRerender = true;
TerminalBuffer.TopLineIndex++;
TerminalBuffer.ShouldRerender = true;
break;
default:
break;
Expand Down Expand Up @@ -122,7 +122,7 @@ private void eventSource_ProjectStarted(object sender, ProjectStartedEventArgs e
return;
}
// Add project
FancyLoggerProjectNode node = new FancyLoggerProjectNode(e);
ProjectNode node = new ProjectNode(e);
projects[id] = node;
// Log
node.ShouldRerender = true;
Expand All @@ -132,7 +132,7 @@ private void eventSource_ProjectFinished(object sender, ProjectFinishedEventArgs
{
// Get project id
int id = e.BuildEventContext!.ProjectInstanceId;
if (!projects.TryGetValue(id, out FancyLoggerProjectNode? node))
if (!projects.TryGetValue(id, out ProjectNode? node))
{
return;
}
Expand All @@ -147,7 +147,7 @@ private void eventSource_TargetStarted(object sender, TargetStartedEventArgs e)
{
// Get project id
int id = e.BuildEventContext!.ProjectInstanceId;
if (!projects.TryGetValue(id, out FancyLoggerProjectNode? node))
if (!projects.TryGetValue(id, out ProjectNode? node))
{
return;
}
Expand All @@ -161,7 +161,7 @@ private void eventSource_TargetFinished(object sender, TargetFinishedEventArgs e
{
// Get project id
int id = e.BuildEventContext!.ProjectInstanceId;
if (!projects.TryGetValue(id, out FancyLoggerProjectNode? node))
if (!projects.TryGetValue(id, out ProjectNode? node))
{
return;
}
Expand All @@ -176,7 +176,7 @@ private void eventSource_TaskStarted(object sender, TaskStartedEventArgs e)
{
// Get project id
int id = e.BuildEventContext!.ProjectInstanceId;
if (!projects.TryGetValue(id, out FancyLoggerProjectNode? node))
if (!projects.TryGetValue(id, out ProjectNode? node))
{
return;
}
Expand All @@ -201,7 +201,7 @@ private void eventSource_MessageRaised(object sender, BuildMessageEventArgs e)
}
// Get project id
int id = e.BuildEventContext!.ProjectInstanceId;
if (!projects.TryGetValue(id, out FancyLoggerProjectNode? node))
if (!projects.TryGetValue(id, out ProjectNode? node))
{
return;
}
Expand All @@ -215,7 +215,7 @@ private void eventSource_WarningRaised(object sender, BuildWarningEventArgs e)
{
// Get project id
int id = e.BuildEventContext!.ProjectInstanceId;
if (!projects.TryGetValue(id, out FancyLoggerProjectNode? node))
if (!projects.TryGetValue(id, out ProjectNode? node))
{
return;
}
Expand All @@ -229,7 +229,7 @@ private void eventSource_ErrorRaised(object sender, BuildErrorEventArgs e)
{
// Get project id
int id = e.BuildEventContext!.ProjectInstanceId;
if (!projects.TryGetValue(id, out FancyLoggerProjectNode? node))
if (!projects.TryGetValue(id, out ProjectNode? node))
{
return;
}
Expand All @@ -247,7 +247,7 @@ private void console_CancelKeyPressed(object? sender, ConsoleCancelEventArgs eve

public void Shutdown()
{
FancyLoggerBuffer.Terminate();
TerminalBuffer.Terminate();
// TODO: Remove. There is a bug that causes switching to main buffer without deleting the contents of the alternate buffer
Console.Clear();
int errorCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using System;
using Microsoft.Build.Framework;

namespace Microsoft.Build.Logging.FancyLogger
namespace Microsoft.Build.Logging.LiveLogger
{

internal class FancyLoggerMessageNode
internal class MessageNode
{
// Use this to change the max lenngth (relative to screen size) of messages
private static int MAX_LENGTH = 3 * Console.BufferWidth;
Expand All @@ -18,13 +18,13 @@ public enum MessageType
Error
}
public string Message;
public FancyLoggerBufferLine? Line;
public TerminalBufferLine? Line;
public MessageType Type;
public string? Code;
public string? FilePath;
public int? LineNumber;
public int? ColumnNumber;
public FancyLoggerMessageNode(LazyFormattedBuildEventArgs args)
public MessageNode(LazyFormattedBuildEventArgs args)
{
Message = args.Message ?? string.Empty;
if (Message.Length > MAX_LENGTH)
Expand Down Expand Up @@ -72,7 +72,7 @@ public string ToANSIString()
}
}

// TODO: Rename to Log after FancyLogger's API becomes internal
// TODO: Rename to Log after LiveLogger's API becomes internal
public void Log()
{
if (Line == null)
Expand Down
Loading

0 comments on commit 7cfb36c

Please sign in to comment.