Skip to content

Commit d74d47a

Browse files
committed
Refactor logging configuration: replace WithLogging method with WithLogLevel for improved clarity and functionality
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
1 parent 84dfe0a commit d74d47a

File tree

3 files changed

+5
-41
lines changed

3 files changed

+5
-41
lines changed

examples/flagd/CommunityToolkit.Aspire.Hosting.Flagd.AppHost/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
var flagd = builder
77
.AddFlagd("flagd")
88
.WithBindFileSync("./flags/")
9-
.WithLogging();
9+
.WithLogLevel(Microsoft.Extensions.Logging.LogLevel.Debug);
1010

1111
builder.Build().Run();

src/CommunityToolkit.Aspire.Hosting.Flagd/FlagdBuilderExtensions.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@ public static IResourceBuilder<FlagdResource> AddFlagd(
4343
.WithArgs("start");
4444
}
4545

46-
/// <summary>
47-
/// Configures logging level for flagd. If a flag or targeting rule isn't proceeding the way you'd expect this can be enabled to get more verbose logging.
48-
/// </summary>
49-
/// <param name="builder">The resource builder.</param>
50-
/// <returns>The <see cref="IResourceBuilder{FlagdResource}"/>.</returns>
51-
public static IResourceBuilder<FlagdResource> WithLogging(
52-
this IResourceBuilder<FlagdResource> builder)
53-
{
54-
ArgumentNullException.ThrowIfNull(builder, nameof(builder));
55-
56-
return builder.WithEnvironment("FLAGD_DEBUG", "true");
57-
}
58-
5946
/// <summary>
6047
/// Configures logging level for flagd. If a flag or targeting rule isn't proceeding the way you'd expect this can be enabled to get more verbose logging.
6148
/// </summary>
@@ -64,7 +51,7 @@ public static IResourceBuilder<FlagdResource> WithLogging(
6451
/// <returns>The <see cref="IResourceBuilder{FlagdResource}"/>.</returns>
6552
/// <exception cref="InvalidOperationException">Thrown if the log level is not valid.</exception>
6653
/// <remarks>Currently only debug is supported.</remarks>
67-
public static IResourceBuilder<FlagdResource> WithLoglevel(
54+
public static IResourceBuilder<FlagdResource> WithLogLevel(
6855
this IResourceBuilder<FlagdResource> builder,
6956
LogLevel logLevel)
7057
{

tests/CommunityToolkit.Aspire.Hosting.Flagd.Tests/AddFlagdTests.cs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -136,26 +136,11 @@ public void AddFlagdAddsStartArgument()
136136
Assert.NotEmpty(commandLineArgs);
137137
}
138138

139-
[Fact]
140-
public void WithLoggingAddsEnvironmentVariable()
141-
{
142-
var builder = DistributedApplication.CreateBuilder();
143-
builder.AddFlagd(FlagdName).WithLogging();
144-
145-
using var app = builder.Build();
146-
147-
var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
148-
var resource = Assert.Single(appModel.Resources.OfType<FlagdResource>());
149-
150-
var envAnnotations = resource.Annotations.OfType<EnvironmentCallbackAnnotation>().ToArray();
151-
Assert.NotEmpty(envAnnotations);
152-
}
153-
154139
[Fact]
155140
public void WithLoglevelDebugAddsEnvironmentVariable()
156141
{
157142
var builder = DistributedApplication.CreateBuilder();
158-
builder.AddFlagd(FlagdName).WithLoglevel(Microsoft.Extensions.Logging.LogLevel.Debug);
143+
builder.AddFlagd(FlagdName).WithLogLevel(Microsoft.Extensions.Logging.LogLevel.Debug);
159144

160145
using var app = builder.Build();
161146

@@ -178,7 +163,7 @@ public void WithLoglevelThrowsForUnsupportedLogLevels(Microsoft.Extensions.Loggi
178163
var builder = DistributedApplication.CreateBuilder();
179164
var flagd = builder.AddFlagd(FlagdName);
180165

181-
var exception = Assert.Throws<InvalidOperationException>(() => flagd.WithLoglevel(logLevel));
166+
var exception = Assert.Throws<InvalidOperationException>(() => flagd.WithLogLevel(logLevel));
182167
Assert.Equal("Only debug log level is supported", exception.Message);
183168
}
184169

@@ -187,7 +172,7 @@ public void WithLoglevelThrowsWhenBuilderIsNull()
187172
{
188173
IResourceBuilder<FlagdResource> builder = null!;
189174

190-
Assert.Throws<ArgumentNullException>(() => builder.WithLoglevel(Microsoft.Extensions.Logging.LogLevel.Debug));
175+
Assert.Throws<ArgumentNullException>(() => builder.WithLogLevel(Microsoft.Extensions.Logging.LogLevel.Debug));
191176
}
192177

193178
[Fact]
@@ -281,14 +266,6 @@ public void AddFlagdThrowsWhenBuilderIsNull()
281266
Assert.Throws<ArgumentNullException>(() => builder.AddFlagd(FlagdName));
282267
}
283268

284-
[Fact]
285-
public void WithLoggingThrowsWhenBuilderIsNull()
286-
{
287-
IResourceBuilder<FlagdResource> builder = null!;
288-
289-
Assert.Throws<ArgumentNullException>(() => builder.WithLogging());
290-
}
291-
292269
[Fact]
293270
public void WithBindFileSyncThrowsWhenBuilderIsNull()
294271
{

0 commit comments

Comments
 (0)