-
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
Fix lazy string format #5924
Fix lazy string format #5924
Conversation
After discussion with Rainer we have decided to delete |
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.
Just making sure I understand this optimization at a high level.
TaskLoggingHelper
usesBuildMessageEventArgs
to log messages, andBuildMessageEventArgs
is aLazyFormattedBuildEventArgs
.GetResourceString
no longer auto-formats becauseTaskLoggingHelper
ultimately uses aLazyFormattedBuildEventArgs
- Any calls to
TaskLoggingHelper.LogMessage
that used to pass in a formatted string have been modified to pass in the resource strings unformatted, thus preventing an unnecessary format
If my understanding is correct, LGTM. I double checked and there shouldn't be any other calls to LogMessage
that pass in a formatted string after this PR merged.
@benvillalobos correct. |
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.
Looks great, thanks!
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.
TaskLoggingHelper
is part of public API surface and - strictly technically - the way it's refactored in this PR is not 100% safe. Say that someone has a derived class:
class MyLoggingHelper : TaskLoggingHelper
{
public override string GetResourceMessage(string resourceName)
{
return "Hello: " + FormatResourceString(resourceName, null);
}
}
Now with the change in this PR calling GetResourceMessage
on such a class will crash with SO exception while previously it worked perfectly fine.
Am I being paranoid? Maybe.
Here's a less contrived example: Changing the formatting behavior can currently be achieved by overriding only FormatResourceString
because then you get GetResourceMessage
for free. With your change it is no longer true. Actually, case in point, check out TaskLoggingHelperExtension
. This class would be broken exactly like so because GetResourceMessage
wouldn't get the overriden behavior.
@ladipro This is very good catch. I will fix it. But truth to be told, the current implementation is counter intuitive - at least to me - as one would expect |
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.
Thank you!
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
In couple of places we have not leveraged LazyFormattedBuildEventArgs properly.
With these changes strings would not be necessary to format, in cases when logging is limited like
/clp:PerformanceSummary
Related issue #2700