Skip to content

Convert to source generation for logging#356

Merged
geofflamrock merged 2 commits intomainfrom
log-source-generators
Sep 3, 2025
Merged

Convert to source generation for logging#356
geofflamrock merged 2 commits intomainfrom
log-source-generators

Conversation

@geofflamrock
Copy link
Owner

@geofflamrock geofflamrock commented Sep 2, 2025

Changes to use source generation for logging to improve performance and consistency of messages. Some slight changes to log levels of some messages which didn't seem right.

@geofflamrock geofflamrock force-pushed the log-source-generators branch 3 times, most recently from c36b51e to d242e34 Compare September 2, 2025 22:10
@geofflamrock geofflamrock requested a review from Copilot September 2, 2025 22:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR converts the codebase from traditional logging calls to source generation for improved performance and better typing. It also removes color formatting from branch and stack names in logging messages to reduce visual distraction, while preserving colors for direct console output.

Key changes:

  • Replace Logger.LogXxx() calls with source-generated logging methods
  • Add [LoggerMessage] attributes for compile-time logging optimization
  • Remove .Branch(), .Stack(), and .Example() extension methods from logging messages

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
OutputStyleExtensionMethods.cs Removes unused Example() extension method
LoggerExtensionMethods.cs Adds source-generated logging methods for common operations
Command.cs Converts error logging to source generation and adds internal logger extensions
ProcessHelpers.cs Converts trace logging to source generation
GitClient.cs Converts debug logging to source generation
Multiple command files Replace traditional logging with source-generated methods and remove color formatting

[LoggerMessage(Level = LogLevel.Information, Message = "Rebasing stack {Stack} for branch line: {SourceBranch} --> {BranchLine}")]
public static partial void RebasingStackForBranchLine(this ILogger logger, string stack, string sourceBranch, string branchLine);

[LoggerMessage(Level = LogLevel.Debug, Message = "No active branches found for branch line.")]
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

The log level should be LogLevel.Warning to match the original code at line 257 which used logger.LogWarning.

Suggested change
[LoggerMessage(Level = LogLevel.Debug, Message = "No active branches found for branch line.")]
[LoggerMessage(Level = LogLevel.Warning, Message = "No active branches found for branch line.")]

Copilot uses AI. Check for mistakes.

internal static partial class LoggerExtensionMethods
{
[LoggerMessage(Level = LogLevel.Trace, Message = "Adding branch {Branch} to stack {Stack}.")]
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

The log level should be LogLevel.Information to match the original code at line 102 which used logger.LogInformation.

Suggested change
[LoggerMessage(Level = LogLevel.Trace, Message = "Adding branch {Branch} to stack {Stack}.")]
[LoggerMessage(Level = LogLevel.Information, Message = "Adding branch {Branch} to stack {Stack}.")]

Copilot uses AI. Check for mistakes.
Comment on lines +125 to +126
[LoggerMessage(Level = LogLevel.Information, Message = "Branch {Branch} added to stack {Stack}.")]
public static partial void BranchAdded(this ILogger logger, string branch, string stack);
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

The original message at line 116 was just 'Branch added' without parameters. The message should be 'Branch added.' to match the original behavior.

Copilot uses AI. Check for mistakes.
@geofflamrock geofflamrock marked this pull request as ready for review September 3, 2025 21:57
@geofflamrock geofflamrock merged commit 7065f49 into main Sep 3, 2025
15 checks passed
@geofflamrock geofflamrock deleted the log-source-generators branch September 3, 2025 22:20
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.

2 participants