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

chore(Orleans.Runtime): Use LoggerMessageGenerator for core logging messages #9316

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

Meir017
Copy link

@Meir017 Meir017 commented Feb 6, 2025

part of #9273

Microsoft Reviewers: Open in CodeFlow

@Meir017
Copy link
Author

Meir017 commented Feb 12, 2025

trying github copilot edits with the following prompt:

Replace usages of ILogger methods with a log method annotated with [LoggerMessage]

if there's a private field of type ILogger make the generated method private partial void
otherwise make it private static partial void as pass the ILogger as the first parameter

If the log method is wrapped in an if (logger.IsEnabled(LogLevel.Debug)) block, remove if statement since it's implicit in the generated method.

when a method call is passed to the log message, create a struct that receives the object and overrides the ToString to call the method that was previously passed to the log message.

the struct should be a nested private readonly struct in the class.

The generated methods should be at the end of the class, the generated struct should be right before the generated methods.

Examples:

Example 1:

_shared.Logger.LogWarning( (int)ErrorCode.Dispatcher_ExtendedMessageProcessing, "Current request has been active for {CurrentRequestActiveTime} for grain {Grain}. Currently executing {BlockingRequest}. Trying to enqueue {Message}.", currentRequestActiveTime, ToDetailedString(), _blockingRequest, message);

should be converted to a method

LogWarningDispatcher_ExtendedMessageProcessing(_shared.Logger, currentRequestActiveTime, new(this), _blockingRequest, message)

where the signature of the method would be

[LoggerMessage(
    EventId = (int)ErrorCode.Dispatcher_ExtendedMessageProcessing,
    Level = LogLevel.Warning,
    Message = "Current request has been active for {CurrentRequestActiveTime} for grain {Grain}. Currently executing {BlockingRequest}. Trying to enqueue {Message}."
)]
private static partial void LogWarningDispatcher_ExtendedMessageProcessing(ILogger logger, TimeSpan currentRequestActiveTime, ActivationDetailsLogValue grain, Message blockingRequest, Message message)
convert all of the remaining logger methods

Example 2:

if (logger.IsEnabled(LogLevel.Debug))
{
    logger.LogDebug("DeactivateActivations: {Count} activations.", list.Count);
}

should be converted to a method

LogDebugDeactivateActivations(list.Count)

where the signature of the method would be

[LoggerMessage(
    Level = LogLevel.Debug,
    Message = "DeactivateActivations: {Count} activations."
)]
private partial void LogDebugDeactivateActivations(int count)

@alrz
Copy link
Member

alrz commented Feb 13, 2025

Could this include some adjustments to messages and log levels to make it more useful to enable information logs on the server? There's a few that considering the content I think are best to be at Trace level.

@Meir017
Copy link
Author

Meir017 commented Feb 14, 2025

Could this include some adjustments to messages and log levels to make it more useful to enable information logs on the server? There's a few that considering the content I think are best to be at Trace level.

@alrz can you comment on the specific log messages?

@Meir017
Copy link
Author

Meir017 commented Feb 14, 2025

@ReubenBond ready for review now, there are a few remaining

#if DEBUG
if (_gateway.logger.IsEnabled(LogLevel.Trace)) _gateway.logger.LogTrace(
#endif

which I didn't modify (maybe in a follow up, and the class ActivationTaskScheduler)

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.

3 participants