fix: Use compact JSON in debug logs

When logging HTTP response/request bodies during communication with
Radarr, Sonarr, etc, use a compact form instead. The previous form had
newlines in it which ended up making the logs vertically very long and
hard to follow.
pull/136/head
Robert Dailey 2 years ago
parent dfd55883f2
commit ba84b07713

@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Docker: `PUID` and `PGID` no longer cause a failure on container start up.
### Fixed
- Use compact JSON for HTTP request/response body in debug log files. This makes logs much easier to
scroll through.
## [2.5.0] - 2022-09-11
### Added

@ -1,5 +1,6 @@
using Flurl;
using Flurl.Http.Configuration;
using Newtonsoft.Json;
using Serilog;
namespace TrashLib.Extensions;
@ -14,12 +15,7 @@ public static class FlurlLogging
{
var url = urlInterceptor(call.Request.Url.Clone());
log.Debug("HTTP Request: {Method} {Url}", call.HttpRequestMessage.Method, url);
var body = call.RequestBody;
if (body is not null)
{
log.Debug("HTTP Body:\n{Body}", body);
}
LogBody(log, call.RequestBody);
};
settings.AfterCallAsync = async call =>
@ -31,7 +27,7 @@ public static class FlurlLogging
var content = call.Response?.ResponseMessage.Content;
if (content is not null)
{
log.Debug("HTTP Body:\n{Body}", await content.ReadAsStringAsync());
LogBody(log, await content.ReadAsStringAsync());
}
};
@ -44,6 +40,17 @@ public static class FlurlLogging
};
}
private static void LogBody(ILogger log, string? body)
{
if (body is null)
{
return;
}
body = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(body));
log.Debug("HTTP Body: {Body}", body);
}
public static Url SanitizeUrl(Url url)
{
// Replace hostname and API key for user privacy

Loading…
Cancel
Save