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

Two bugfixes for logging generator #51963

Merged
merged 2 commits into from
Apr 29, 2021
Merged

Conversation

maryamariyan
Copy link
Member

@maryamariyan maryamariyan commented Apr 27, 2021

cc: @geeknoid, @gfoidl

Fixes: #51917, #51965

@ghost
Copy link

ghost commented Apr 27, 2021

Tagging subscribers to this area: @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details
  • replace nameof(Generator) with "LoggerMessage"
  • bugfix: up to 6 params, use LoggerMessage.Define
  • bugfix: __Enumerate method was missing for IEnumerable arguments
  • change __Enumerate method: made part of a utility method, generated once in __LoggerMessageGenerator
  • minor cleanup

cc: @geeknoid

Author: maryamariyan
Assignees: -
Labels:

area-Extensions-Logging

Milestone: -

@maryamariyan maryamariyan changed the title Bugfixes for logging generator Two bugfixes for logging generator Apr 27, 2021
@@ -39,7 +39,7 @@ public void Execute(GeneratorExecutionContext context)
var e = new Emitter();
string result = e.Emit(logClasses, context.CancellationToken);

context.AddSource(nameof(LoggerMessageGenerator), SourceText.From(result, Encoding.UTF8));
context.AddSource("LoggerMessage", SourceText.From(result, Encoding.UTF8));
Copy link
Member Author

@maryamariyan maryamariyan Apr 27, 2021

Choose a reason for hiding this comment

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

Just so the generated file name would become LoggerMessage.cs instead of LoggerMessageGenerator.cs

@@ -443,63 +445,56 @@ static string GetLogLevel(LoggerMethod lm)
}
}

private void GenEnumerationHelper(LoggerClass lc)
Copy link
Member Author

Choose a reason for hiding this comment

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

The enumeration helper is either generated (only once), or not at all into __LoggerMessageGenerator

- bugfix: up to 6 params, use LoggerMessage.Define
- bugfix: "__Enumerate" method was missing for IEnumerable arguments
- change "__Enumerate" method: made part of a utility method, generated once in __LoggerMessageGenerator
Copy link
Member

@gfoidl gfoidl left a comment

Choose a reason for hiding this comment

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

One (minor) suggestion, otherwise LGTM.

Thanks!

[{_generatedCodeAttribute}]
private static string __Enumerate(global::System.Collections.IEnumerable? enumerable)
[{_generatedCodeAttribute}]
internal static class __LoggerMessageGenerator
Copy link
Member

Choose a reason for hiding this comment

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

Just thinking out loud here, but I almost wonder if this deserves to be a public API in our library instead of generating this code into the user's project.

I started by thinking "is putting this in the global namespace the right thing to do?" And then that quickly led to "why are we generating this code when it never changes based on the user's types?"

Copy link
Member Author

@maryamariyan maryamariyan Apr 29, 2021

Choose a reason for hiding this comment

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

In the very first API review proposal (Refer to comment #36022 (comment)), we proposed this static ArgumentFormatter.Enumerate(..) helper method which we said would only be used in the generated code.

The consensus back then was for such cases to just generate them if/when needed.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

Looks good. Just a nit and a thought.

@maryamariyan maryamariyan merged commit 3245528 into dotnet:main Apr 29, 2021
@maryamariyan maryamariyan deleted the bugfixes branch April 29, 2021 01:55
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging-Generator doesn't use LoggerMessage.Define for > 1 template argument
6 participants