-
Notifications
You must be signed in to change notification settings - Fork 53
Add specific logging categories for Worker.Grpc and orchestration logs with backward-compatible opt-in #551
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0ece6f4
Initial plan
Copilot 80b3351
Add logging category options and dual-category logger implementation
Copilot 9e2f167
Merge branch 'main' into copilot/make-logging-categories-specific
YunchuWang 6022cd9
Merge branch 'main' into copilot/make-logging-categories-specific
YunchuWang 7a7cf8a
Address PR feedback: fix parameter shadowing, remove unused code
Copilot 950269e
Add integration tests for GrpcDurableTaskWorker dual-category logging
Copilot 57763f7
Potential fix for pull request finding 'Useless assignment to local v…
YunchuWang c862143
cleanup
YunchuWang ec40f9f
Merge branch 'copilot/make-logging-categories-specific' of https://gi…
YunchuWang aa7f0ad
Merge branch 'main' into copilot/make-logging-categories-specific
YunchuWang 2e02259
Extend logging categories to TaskOrchestrationContextWrapper (WIP)
Copilot dcd6a1c
Complete logging categories extension to TaskOrchestrationContextWrapper
Copilot dd1fe75
Merge branch 'main' into copilot/make-logging-categories-specific
YunchuWang bf8d1f3
Revert "Complete logging categories extension to TaskOrchestrationCon…
YunchuWang f66b191
Revert "Extend logging categories to TaskOrchestrationContextWrapper …
YunchuWang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.DurableTask.Worker.Grpc; | ||
|
|
||
| /// <summary> | ||
| /// A logger wrapper that emits logs to both a primary (new) category and an optional legacy category. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This logger is used to maintain backward compatibility while transitioning to more specific logging categories. | ||
| /// When legacy categories are enabled, log messages are written to both the new specific category | ||
| /// (e.g., "Microsoft.DurableTask.Worker.Grpc") and the legacy broad category (e.g., "Microsoft.DurableTask"). | ||
| /// </remarks> | ||
| sealed class DualCategoryLogger : ILogger | ||
| { | ||
| readonly ILogger primaryLogger; | ||
| readonly ILogger? legacyLogger; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="DualCategoryLogger"/> class. | ||
| /// </summary> | ||
| /// <param name="primaryLogger">The primary logger with the new category.</param> | ||
| /// <param name="legacyLogger">The optional legacy logger with the old category.</param> | ||
| public DualCategoryLogger(ILogger primaryLogger, ILogger? legacyLogger) | ||
| { | ||
| this.primaryLogger = Check.NotNull(primaryLogger); | ||
| this.legacyLogger = legacyLogger; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public IDisposable? BeginScope<TState>(TState state) | ||
| where TState : notnull | ||
| { | ||
| IDisposable? primaryScope = this.primaryLogger.BeginScope(state); | ||
| IDisposable? legacyScope = this.legacyLogger?.BeginScope(state); | ||
|
|
||
| if (primaryScope is not null && legacyScope is not null) | ||
| { | ||
| return new CompositeDisposable(primaryScope, legacyScope); | ||
| } | ||
|
|
||
| return primaryScope ?? legacyScope; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool IsEnabled(LogLevel logLevel) | ||
| { | ||
| // Return true if either logger is enabled at this level | ||
| return this.primaryLogger.IsEnabled(logLevel) || | ||
| (this.legacyLogger?.IsEnabled(logLevel) ?? false); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public void Log<TState>( | ||
| LogLevel logLevel, | ||
| EventId eventId, | ||
| TState state, | ||
| Exception? exception, | ||
| Func<TState, Exception?, string> formatter) | ||
| { | ||
| // Log to primary logger | ||
| if (this.primaryLogger.IsEnabled(logLevel)) | ||
| { | ||
| this.primaryLogger.Log(logLevel, eventId, state, exception, formatter); | ||
| } | ||
|
|
||
| // Log to legacy logger if enabled | ||
| if (this.legacyLogger?.IsEnabled(logLevel) ?? false) | ||
| { | ||
| this.legacyLogger.Log(logLevel, eventId, state, exception, formatter); | ||
| } | ||
| } | ||
|
|
||
| sealed class CompositeDisposable : IDisposable | ||
| { | ||
| readonly IDisposable first; | ||
| readonly IDisposable second; | ||
|
|
||
| public CompositeDisposable(IDisposable first, IDisposable second) | ||
| { | ||
| this.first = first; | ||
| this.second = second; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| this.first.Dispose(); | ||
| this.second.Dispose(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.