Skip to content

Enable logging instance properties in default text loggers#5414

Merged
rainersigwald merged 62 commits intodotnet:masterfrom
laurenprinn:logger_updates
Jul 20, 2020
Merged

Enable logging instance properties in default text loggers#5414
rainersigwald merged 62 commits intodotnet:masterfrom
laurenprinn:logger_updates

Conversation

@laurenprinn
Copy link
Copy Markdown
Contributor

@laurenprinn laurenprinn commented Jun 8, 2020

Edits console logger such that various properties can be output in an error or warning message. The properties are determined by an item "outputProperties" defined by the project. Ex:
Program.cs(14,13): error CS0103: The name 'Consol' does not exist in the current context [C:\Users\t-laprin\source\repos\tester_app\tester_app\tester_app.csproj SchemaVersion:2.0 TargetFramework:netcoreapp3.0 ]

I don't have write permission to Link an issue to this, but this would be the issue it should link to: #3015

Lauren Prinn and others added 18 commits June 3, 2020 11:19
…a message. Note that this was added as a parameter because this class does not have access to the datastructures holding the target framework mappings.
…t framework and to print the target framework along with an error or warning message
…al errors and warning and to separate the error/warning summary by target framework
…t Framework information being printed on the console
…r/warning summary display to properly show.
grammar fix

Co-authored-by: Forgind <Forgind@users.noreply.github.com>
…y name. Replaced a forEach loop with a TryGet() for time improvement.
…tEventMessage. Increased efficiency by using TryGetValue and TryAdd instead of using containsKey
…this was not super helpful and could have potential issues with people's regex expressions
…n warning/error messages based on a customizable item defined in a project.
@laurenprinn laurenprinn marked this pull request as draft June 9, 2020 17:18
Lauren Prinn added 2 commits June 9, 2020 17:58
…s to ensure that regex expressions can easily parse the file path but also makes it a bit easier for the user to read
@laurenprinn laurenprinn marked this pull request as ready for review June 9, 2020 23:05
Copy link
Copy Markdown
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strong start! I don't understand why you made some of the changes, but I'll look again later to see if it makes sense then.

Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/BaseConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Shared/EventArgsFormatting.cs Outdated
}
}
#endif No newline at end of file
#endif
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo changes like this or extra spaces, please

Comment thread src/Framework/LazyFormattedBuildEventArgs.cs Outdated
Comment thread src/Framework/BuildErrorEventArgs.cs Outdated
Comment thread src/Build/Logging/SerialConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
@cdmihai
Copy link
Copy Markdown
Contributor

cdmihai commented Jun 25, 2020

Wouldn't it be better if the engine computed this string, rather than a specific logger? If loggers are responsible for computing it, then everybody who writes a logger has to duplicate this logic. If the engine computes it, then it's in a single place.

ProjectStartedEventArgs can hold the computed string for the project instance it represents. The LoggingService can hold the string cache to avoid recomputations and LogProjectStarted would compute it.

Another benefit of putting it in the ProjectStartedEventArgs is that it would make it super easy for the bin logger to display the string next to each Project node (@KirillOsenkov).

Taking it even further, it could even be a property of ProjectInstance and / or Project. This would help all the tools out there to provide this info in their UIs. ProjectStartedEventArgs would enable loggers to display it, ProjectInstance/Project would enable msbuild API users to display it (Visual Studio, QuickBuild, dotnet CLI?, etc).

if (string.Equals((string)item.Key, "LogOutputProperties", StringComparison.OrdinalIgnoreCase))
{
// Add the item value to the string to be printed in error/warning messages
logOutputProperties.Append(" ").Append(itemVal.ItemSpec);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to allow configuring the separator via a property (like MSBuildProjectConfigurationDescriptionSeparator). Default to space if none is set.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes parsing harder so I think I'm against it.

@rainersigwald
Copy link
Copy Markdown
Member

ProjectStartedEventArgs can hold the computed string for the project instance it represents. The LoggingService can hold the string cache to avoid recomputations and LogProjectStarted would compute it.

This is a nice design, I think.

Taking it even further, it could even be a property of ProjectInstance and / or Project. This would help all the tools out there to provide this info in their UIs. ProjectStartedEventArgs would enable loggers to display it, ProjectInstance/Project would enable msbuild API users to display it (Visual Studio, QuickBuild, dotnet CLI?, etc).

Maybe, but right now I think I prefer leaving it at the logging level (in the event).

@rainersigwald
Copy link
Copy Markdown
Member

Talked this over with @laurenprinn and others. I like pushing it to the LoggingService, but that doesn't solve the whole problem, because it's only easy to do that for the ProjectStarted event. When logging, though, we'll really want this for errors/warnings/messages, too. So the logger would still have to preserve/restore it.

We could add it to a deep base class like BuildEventContext or LazyFormattedBuildEventArgs, but that would potentially spend a fair amount of memory for minimal benefit when using other loggers (like the VS logger).

So let's go with this implementation for now and we can potentially improve it further in the future.

Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Shared/EventArgsFormatting.cs Outdated
Comment thread src/Shared/EventArgsFormatting.cs Outdated
Comment thread src/Shared/EventArgsFormatting.cs Outdated
Comment thread src/Shared/EventArgsFormatting.cs Outdated
Copy link
Copy Markdown
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many nits, looking great overall!

Comment thread src/Build.UnitTests/ConsoleLogger_Tests.cs Outdated
Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs
int projectContextId = e.BuildEventContext.ProjectContextId;

// Create the value to be added to the propertyOutputMap
StringBuilder msBuildProjectConfigurationDescription = new StringBuilder();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, works on my machine™:

Suggested change
StringBuilder msBuildProjectConfigurationDescription = new StringBuilder();
using var msBuildProjectConfigurationDescription = new ReuseableStringBuilder();

Comment thread src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs Outdated
Comment thread src/Build/Logging/SerialConsoleLogger.cs Outdated
Comment thread src/MSBuild.UnitTests/XMake_Tests.cs
Comment thread src/Shared/EventArgsFormatting.cs Outdated
Comment thread src/Shared/EventArgsFormatting.cs Outdated
@rainersigwald rainersigwald changed the title Logger updates Enable logging instance properties in default text loggers Jul 20, 2020
@rainersigwald rainersigwald merged commit aa56a5a into dotnet:master Jul 20, 2020
@ghost ghost added this to the current-release milestone Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants