Skip to content

Commit

Permalink
Changing to Source Generation logging.
Browse files Browse the repository at this point in the history
Signed-off-by: André Silva <[email protected]>
  • Loading branch information
askpt committed Oct 18, 2024
1 parent 54c145e commit 55582d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OpenFeature.Internal;

internal sealed class FeatureLifecycleManager : IFeatureLifecycleManager
internal sealed partial class FeatureLifecycleManager : IFeatureLifecycleManager
{
private readonly Api _featureApi;
private readonly IServiceProvider _serviceProvider;
Expand All @@ -19,7 +19,7 @@ public FeatureLifecycleManager(Api featureApi, IServiceProvider serviceProvider,
/// <inheritdoc />
public async ValueTask EnsureInitializedAsync(CancellationToken cancellationToken = default)
{
_logger.LogInformation("Starting initialization of the feature provider");
this.LogStartingInitializationOfFeatureProvider();
var featureProvider = _serviceProvider.GetService<FeatureProvider>();
if (featureProvider == null)
{
Expand All @@ -31,7 +31,13 @@ public async ValueTask EnsureInitializedAsync(CancellationToken cancellationToke
/// <inheritdoc />
public async ValueTask ShutdownAsync(CancellationToken cancellationToken = default)
{
_logger.LogInformation("Shutting down the feature provider.");
this.LogShuttingDownFeatureProvider();
await _featureApi.ShutdownAsync().ConfigureAwait(false);
}

[LoggerMessage(200, LogLevel.Information, "Starting initialization of the feature provider")]
partial void LogStartingInitializationOfFeatureProvider();

[LoggerMessage(200, LogLevel.Information, "Shutting down the feature provider")]
partial void LogShuttingDownFeatureProvider();
}
16 changes: 11 additions & 5 deletions src/OpenFeature.Hosting/HostedFeatureLifecycleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace OpenFeature;

/// <summary>
/// A hosted service that manages the lifecycle of features within the application.
/// It ensures that features are properly initialized when the service starts
/// A hosted service that manages the lifecycle of features within the application.
/// It ensures that features are properly initialized when the service starts
/// and gracefully shuts down when the service stops.
/// </summary>
public sealed class HostedFeatureLifecycleService : IHostedLifecycleService
public sealed partial class HostedFeatureLifecycleService : IHostedLifecycleService
{
private readonly ILogger<HostedFeatureLifecycleService> _logger;
private readonly IFeatureLifecycleManager _featureLifecycleManager;
Expand Down Expand Up @@ -74,7 +74,7 @@ private async Task InitializeIfStateMatchesAsync(FeatureStartState expectedState
{
if (_featureLifecycleStateOptions.Value.StartState == expectedState)
{
_logger.LogInformation("Initializing the Feature Lifecycle Manager for state {State}.", expectedState);
this.LogInitializingFeatureLifecycleManager(expectedState);
await _featureLifecycleManager.EnsureInitializedAsync(cancellationToken).ConfigureAwait(false);
}
}
Expand All @@ -86,8 +86,14 @@ private async Task ShutdownIfStateMatchesAsync(FeatureStopState expectedState, C
{
if (_featureLifecycleStateOptions.Value.StopState == expectedState)
{
_logger.LogInformation("Shutting down the Feature Lifecycle Manager for state {State}.", expectedState);
this.LogShuttingDownFeatureLifecycleManager(expectedState);
await _featureLifecycleManager.ShutdownAsync(cancellationToken).ConfigureAwait(false);
}
}

[LoggerMessage(200, LogLevel.Information, "Initializing the Feature Lifecycle Manager for state {State}.")]
partial void LogInitializingFeatureLifecycleManager(FeatureStartState state);

[LoggerMessage(200, LogLevel.Information, "Shutting down the Feature Lifecycle Manager for state {State}")]
partial void LogShuttingDownFeatureLifecycleManager(FeatureStopState state);
}

0 comments on commit 55582d7

Please sign in to comment.