Skip to content

Commit 2103344

Browse files
committed
Further reduce tests verbosity
1 parent 1f474d2 commit 2103344

File tree

10 files changed

+35
-20
lines changed

10 files changed

+35
-20
lines changed

src/Examples/JsonApiDotNetCoreExample/Startup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Startup(IHostingEnvironment env)
2828
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
2929
{
3030
var loggerFactory = new LoggerFactory();
31-
loggerFactory.AddConsole(LogLevel.Trace);
31+
loggerFactory.AddConsole(LogLevel.Warning);
3232

3333
services
3434
.AddSingleton<ILoggerFactory>(loggerFactory)
@@ -57,7 +57,6 @@ public virtual void Configure(
5757
context.Database.EnsureCreated();
5858

5959
loggerFactory.AddConsole(Config.GetSection("Logging"));
60-
loggerFactory.AddDebug();
6160

6261
app.UseJsonApi();
6362
}

src/Examples/NoEntityFrameworkExample/Startup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using JsonApiDotNetCore.Extensions;
1+
using JsonApiDotNetCore.Extensions;
22
using JsonApiDotNetCore.Services;
33
using JsonApiDotNetCoreExample.Data;
44
using JsonApiDotNetCoreExample.Models;
@@ -55,7 +55,6 @@ public virtual IServiceProvider ConfigureServices(IServiceCollection services)
5555
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, AppDbContext context)
5656
{
5757
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
58-
loggerFactory.AddDebug();
5958

6059
context.Database.EnsureCreated();
6160

src/Examples/OperationsExample/Startup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Startup(IHostingEnvironment env)
2727
public virtual IServiceProvider ConfigureServices(IServiceCollection services)
2828
{
2929
var loggerFactory = new LoggerFactory();
30-
loggerFactory.AddConsole(LogLevel.Trace);
30+
loggerFactory.AddConsole(LogLevel.Warning);
3131

3232
services.AddSingleton<ILoggerFactory>(loggerFactory);
3333

@@ -47,7 +47,6 @@ public virtual void Configure(
4747
context.Database.EnsureCreated();
4848

4949
loggerFactory.AddConsole(Config.GetSection("Logging"));
50-
loggerFactory.AddDebug();
5150
app.UseJsonApi();
5251
}
5352

src/Examples/ReportsExample/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Logging": {
33
"IncludeScopes": false,
44
"LogLevel": {
5-
"Default": "Information"
5+
"Default": "Warning"
66
}
77
}
88
}

src/JsonApiDotNetCore/Serialization/JsonApiSerializer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ private string GetErrorJson(object responseObject, ILogger logger)
6565
}
6666
else
6767
{
68-
logger?.LogInformation("Response was not a JSONAPI entity. Serializing as plain JSON.");
68+
if (logger?.IsEnabled(LogLevel.Information) == true)
69+
{
70+
logger.LogInformation("Response was not a JSONAPI entity. Serializing as plain JSON.");
71+
}
72+
6973
return JsonConvert.SerializeObject(responseObject);
7074
}
7175
}

src/JsonApiDotNetCore/Services/EntityResourceService.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ public virtual async Task<object> GetRelationshipAsync(TId id, string relationsh
8989

9090
if (relationshipName == null)
9191
throw new JsonApiException(422, "Relationship name not specified.");
92-
93-
_logger.LogTrace($"Looking up '{relationshipName}'...");
92+
if (_logger.IsEnabled(LogLevel.Trace))
93+
{
94+
_logger.LogTrace($"Looking up '{relationshipName}'...");
95+
}
9496

9597
var entity = await _entities.GetAndIncludeAsync(id, relationshipName);
9698
// TODO: it would be better if we could distinguish whether or not the relationship was not found,
@@ -166,7 +168,10 @@ protected virtual async Task<IEnumerable<T>> ApplyPageQueryAsync(IQueryable<T> e
166168
if (!pageManager.IsPaginated)
167169
return await _entities.ToListAsync(entities);
168170

169-
_logger?.LogInformation($"Applying paging query. Fetching page {pageManager.CurrentPage} with {pageManager.PageSize} entities");
171+
if (_logger?.IsEnabled(LogLevel.Information) == true)
172+
{
173+
_logger?.LogInformation($"Applying paging query. Fetching page {pageManager.CurrentPage} with {pageManager.PageSize} entities");
174+
}
170175

171176
return await _entities.PageAsync(entities, pageManager.PageSize, pageManager.CurrentPage);
172177
}

src/JsonApiDotNetCore/Services/QueryAccessor.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ public bool TryGetValue<T>(string key, out T value)
4545
var stringValue = GetFilterValue(key);
4646
if (stringValue == null)
4747
{
48-
_logger.LogInformation($"'{key}' was not found in the query collection");
48+
if (_logger.IsEnabled(LogLevel.Information))
49+
{
50+
_logger.LogInformation($"'{key}' was not found in the query collection");
51+
}
52+
4953
return false;
5054
}
5155

@@ -56,7 +60,12 @@ public bool TryGetValue<T>(string key, out T value)
5660
}
5761
catch (FormatException)
5862
{
59-
_logger.LogInformation($"'{value}' is not a valid '{typeof(T).Name}' value for query parameter {key}");
63+
if (_logger.IsEnabled(LogLevel.Information))
64+
{
65+
_logger.LogInformation(
66+
$"'{value}' is not a valid '{typeof(T).Name}' value for query parameter {key}");
67+
}
68+
6069
return false;
6170
}
6271
}

test/JsonApiDotNetCoreExampleTests/Helpers/Startups/MetaStartup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public MetaStartup(IHostingEnvironment env)
2020
public override IServiceProvider ConfigureServices(IServiceCollection services)
2121
{
2222
var loggerFactory = new LoggerFactory();
23-
loggerFactory.AddConsole(LogLevel.Trace);
23+
loggerFactory.AddConsole(LogLevel.Warning);
2424

2525
services
2626
.AddSingleton<ILoggerFactory>(loggerFactory)

test/JsonApiDotNetCoreExampleTests/appsettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"Logging": {
66
"IncludeScopes": false,
77
"LogLevel": {
8-
"Default": "Error",
9-
"System": "Information",
10-
"Microsoft": "Information"
8+
"Default": "Warning",
9+
"System": "Warning",
10+
"Microsoft": "Warning"
1111
}
1212
}
1313
}

test/NoEntityFrameworkTests/appsettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"Logging": {
66
"IncludeScopes": false,
77
"LogLevel": {
8-
"Default": "Debug",
9-
"System": "Information",
10-
"Microsoft": "Information"
8+
"Default": "Warning",
9+
"System": "Warning",
10+
"Microsoft": "Warning"
1111
}
1212
}
1313
}

0 commit comments

Comments
 (0)