Skip to content

Commit

Permalink
Create explicit logger forwarder for buildcheck (#10084)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKrivanek committed May 2, 2024
1 parent 300b2a8 commit ef8b6a4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
20 changes: 16 additions & 4 deletions src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2989,10 +2989,22 @@ private ILoggingService CreateLoggingService(
((IBuildComponentHost)this).GetComponent(BuildComponentType.BuildCheckManagerProvider) as IBuildCheckManagerProvider;
buildCheckManagerProvider!.Instance.SetDataSource(BuildCheckDataSource.EventArgs);

loggers = (loggers ?? Enumerable.Empty<ILogger>()).Concat(new[]
{
new BuildCheckConnectorLogger(new AnalyzerLoggingContextFactory(loggingService), buildCheckManagerProvider.Instance)
});
// We do want to dictate our own forwarding logger (otherwise CentralForwardingLogger with minimum transferred importance MessageImportnace.Low is used)
// In the future we might optimize for single, in-node build scenario - where forwarding logger is not needed (but it's just quick pass-through)
LoggerDescription forwardingLoggerDescription = new LoggerDescription(
loggerClassName: typeof(BuildCheckForwardingLogger).FullName,
loggerAssemblyName: typeof(BuildCheckForwardingLogger).GetTypeInfo().Assembly.GetName().FullName,
loggerAssemblyFile: null,
loggerSwitchParameters: null,
verbosity: LoggerVerbosity.Quiet);

ILogger buildCheckLogger =
new BuildCheckConnectorLogger(new AnalyzerLoggingContextFactory(loggingService),
buildCheckManagerProvider.Instance);

ForwardingLoggerRecord[] forwardingLogger = { new ForwardingLoggerRecord(buildCheckLogger, forwardingLoggerDescription) };

forwardingLoggers = forwardingLoggers?.Concat(forwardingLogger) ?? forwardingLogger;
}

try
Expand Down
5 changes: 5 additions & 0 deletions src/Build/BackEnd/Components/Logging/LoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Reflection;
using System.Threading;
using Microsoft.Build.BackEnd.Components.RequestBuilder;
using Microsoft.Build.BuildCheck.Infrastructure;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
Expand Down Expand Up @@ -1758,6 +1759,10 @@ private void UpdateMinimumMessageImportance(ILogger logger)
Build.Logging.ConsoleLogger consoleLogger => consoleLogger.GetMinimumMessageImportance(),
Build.Logging.ConfigurableForwardingLogger forwardingLogger => forwardingLogger.GetMinimumMessageImportance(),

// The BuildCheck connector logger consumes only high priority messages.
BuildCheckForwardingLogger => MessageImportance.High,
BuildCheck.Infrastructure.BuildCheckConnectorLogger => MessageImportance.High,

// Central forwarding loggers are used in worker nodes if logging verbosity could not be optimized, i.e. in cases
// where we must log everything. They can be ignored in inproc nodes.
CentralForwardingLogger => (_nodeId > 1 ? MessageImportance.Low : null),
Expand Down
19 changes: 19 additions & 0 deletions src/Build/BuildCheck/Infrastructure/BuildCheckForwardingLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.BackEnd.Logging;

namespace Microsoft.Build.BuildCheck.Infrastructure;

/// <summary>
/// Forwarding logger for the build check infrastructure.
/// For now we jus want to forward all events, while disable verbose logging of tasks.
/// In the future we may need more specific behavior.
/// </summary>
internal class BuildCheckForwardingLogger : CentralForwardingLogger
{ }
1 change: 1 addition & 0 deletions src/Build/Microsoft.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<Compile Include="BuildCheck\Acquisition\IBuildCheckAcquisitionModule.cs" />
<Compile Include="BuildCheck\Analyzers\SharedOutputPathAnalyzer.cs" />
<Compile Include="BuildCheck\Infrastructure\BuildCheckConfigurationException.cs" />
<Compile Include="BuildCheck\Infrastructure\BuildCheckForwardingLogger.cs" />
<Compile Include="BuildCheck\Infrastructure\BuildEventsProcessor.cs" />
<Compile Include="BuildCheck\Infrastructure\IBuildCheckManagerProvider.cs" />
<Compile Include="BuildCheck\Infrastructure\NullBuildCheckManager.cs" />
Expand Down
14 changes: 11 additions & 3 deletions src/MSBuild.UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2626,16 +2626,24 @@ public void EndToEndVersionMessage(string arguments, bool shouldContainVersionMe
[InlineData("/v:normal", MessageImportance.Normal)]
[InlineData("/v:minimal", MessageImportance.High)]
[InlineData("/v:quiet", MessageImportance.High - 1)]

[InlineData("/v:diagnostic /bl", MessageImportance.Low)]
[InlineData("/v:detailed /bl", MessageImportance.Low)]
[InlineData("/v:normal /bl", MessageImportance.Low)] // v:normal but with binary logger so everything must be logged
[InlineData("/v:minimal /bl", MessageImportance.Low)] // v:minimal but with binary logger so everything must be logged
[InlineData("/v:quiet /bl", MessageImportance.Low)] // v:quiet but with binary logger so everything must be logged

[InlineData("/v:diagnostic /analyze", MessageImportance.Low)]
[InlineData("/v:detailed /analyze", MessageImportance.Low)]
[InlineData("/v:normal /analyze", MessageImportance.Low)] // v:normal but with analyzers so everything must be logged
[InlineData("/v:minimal /analyze", MessageImportance.Low)] // v:minimal but with analyzers so everything must be logged
[InlineData("/v:quiet /analyze", MessageImportance.Low)] // v:quiet but with analyzers so everything must be logged
[InlineData("/v:normal /analyze", MessageImportance.Normal)]
[InlineData("/v:minimal /analyze", MessageImportance.High)]
[InlineData("/v:quiet /analyze", MessageImportance.High)]

[InlineData("/v:diagnostic /tl", MessageImportance.Low)]
[InlineData("/v:detailed /tl", MessageImportance.Low)]
[InlineData("/v:normal /tl", MessageImportance.Normal)]
[InlineData("/v:minimal /tl", MessageImportance.High)]
[InlineData("/v:quiet /tl", MessageImportance.High - 1)]
public void EndToEndMinimumMessageImportance(string arguments, MessageImportance expectedMinimumMessageImportance)
{
using TestEnvironment testEnvironment = UnitTests.TestEnvironment.Create();
Expand Down

0 comments on commit ef8b6a4

Please sign in to comment.