Skip to content

Commit

Permalink
Remove request logging from API
Browse files Browse the repository at this point in the history
  • Loading branch information
martyn-w committed Sep 17, 2024
1 parent eae960d commit ac28ef0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;
using GetIntoTeachingApi.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -28,7 +28,6 @@ public RequestResponseLoggingMiddleware(

public async Task Invoke(HttpContext context)
{
await LogRequest(context);
await LogResponse(context);
}

Expand Down Expand Up @@ -83,18 +82,6 @@ private bool ShouldLogPayload(string method, string path)
return _config.CompactLoggingPatterns.All(regex => !regex.IsMatch(input));
}

private async Task LogRequest(HttpContext context)
{
context.Request.EnableBuffering();

// Copy request body stream, resetting position for next middleware.
await using var stream = _recyclableMemoryStreamManager.GetStream();
await context.Request.Body.CopyToAsync(stream);
context.Request.Body.Position = 0;

LogInformation("HTTP Request", ReadStream(stream), context.Request);
}

private async Task LogResponse(HttpContext context)
{
// Keep track of the original response body stream (its read-once).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public async Task Invoke_WithJsonPayloadAndCompactLoggingPath_LogsRequestAndResp
_context.Request.QueryString,
Payload = string.Empty,
};

_mockLogger.VerifyInformationWasCalled($"HTTP Request: {expectedInfo}");

_mockLogger.VerifyInformationWasCalled($"HTTP Response: {expectedInfo}");
}

Expand Down Expand Up @@ -88,8 +87,7 @@ public async Task Invoke_WithJsonPayload_LogsRequestAndResponseWithRedactedPaylo
_context.Request.QueryString,
Payload = redactedJson,
};

_mockLogger.VerifyInformationWasCalled($"HTTP Request: {expectedInfo}");

_mockLogger.VerifyInformationWasCalled($"HTTP Response: {expectedInfo}");
}

Expand All @@ -108,8 +106,7 @@ public async Task Invoke_WithNonJsonPayload_LogsRequestAndResponseWithEmptyPaylo
_context.Request.QueryString,
Payload = string.Empty,
};

_mockLogger.VerifyInformationWasCalled($"HTTP Request: {expectedInfo}");

_mockLogger.VerifyInformationWasCalled($"HTTP Response: {expectedInfo}");
}

Expand Down

0 comments on commit ac28ef0

Please sign in to comment.