Revert "Remove logging Requests"

This reverts commit d0aad46694ba2047b518ea1937a4b04a92b9a253.
This commit is contained in:
CWX
2025-04-23 15:35:39 +01:00
parent e5ce7c990a
commit 690f9f3e83
4 changed files with 72 additions and 0 deletions
@@ -0,0 +1,6 @@
namespace SPTarkov.Server.Core.Servers.Http;
// This is a dummy class to use for SourceContext in Serilog, do not remove!
public class RequestLogger
{
}
@@ -26,6 +26,7 @@ public class SptHttpListener : IHttpListener
protected readonly JsonUtil _jsonUtil;
protected readonly LocalisationService _localisationService;
protected readonly ISptLogger<SptHttpListener> _logger;
protected readonly ISptLogger<RequestLogger> _requestLogger;
protected readonly HttpRouter _router;
@@ -35,6 +36,7 @@ public class SptHttpListener : IHttpListener
HttpRouter httpRouter,
IEnumerable<ISerializer> serializers,
ISptLogger<SptHttpListener> logger,
ISptLogger<RequestLogger> requestsLogger,
JsonUtil jsonUtil,
HttpResponseUtil httpHttpResponseUtil,
LocalisationService localisationService
@@ -43,6 +45,7 @@ public class SptHttpListener : IHttpListener
_router = httpRouter;
_serializers = serializers;
_logger = logger;
_requestLogger = requestsLogger;
_httpResponseUtil = httpHttpResponseUtil;
_localisationService = localisationService;
_jsonUtil = jsonUtil;
@@ -153,6 +156,7 @@ public class SptHttpListener : IHttpListener
{
// Send only raw response without transformation
SendJson(resp, output, sessionID);
LogRequest(req, output);
return;
}
@@ -167,6 +171,8 @@ public class SptHttpListener : IHttpListener
{
SendZlibJson(resp, output, sessionID);
}
LogRequest(req, output);
}
/// <summary>
@@ -179,6 +185,20 @@ public class SptHttpListener : IHttpListener
return req.Headers.TryGetValue("responsecompressed", out var value) && value == "0";
}
/// <summary>
/// Log request if enabled
/// </summary>
/// <param name="req"> Log request if enabled </param>
/// <param name="output"> Output string </param>
protected void LogRequest(HttpRequest req, string output)
{
if (ProgramStatics.ENTRY_TYPE() != EntryType.RELEASE)
{
var log = new Response(req.Method, output.Substring(0, Math.Min(output.Length, 8000)));
_requestLogger.Info($"RESPONSE={_jsonUtil.Serialize(log)}");
}
}
public string GetResponse(string sessionID, HttpRequest req, string? body)
{
var output = _router.GetResponse(req, sessionID, body, out var deserializedObject);
@@ -190,6 +210,13 @@ public class SptHttpListener : IHttpListener
output = _httpResponseUtil.GetBody<object?>(null, BackendErrorCodes.HTTPNotFound, $"UNHANDLED RESPONSE: {req.Path.ToString()}");
}
if (ProgramStatics.ENTRY_TYPE() != EntryType.RELEASE)
{
// Parse quest info into object
var log = new Request(req.Method, new RequestData(req.Path, req.Headers, deserializedObject));
_requestLogger.Info($"REQUEST={_jsonUtil.Serialize(log)}");
}
return output;
}
@@ -26,6 +26,12 @@
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "StartsWith(SourceContext, 'SPTarkov.Server.Core.Servers.Http.RequestLogger')"
}
},
{
"Name": "ByExcluding",
"Args": {
@@ -54,6 +60,33 @@
}
}
},
{
"Name": "Logger",
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "StartsWith(SourceContext, 'SPTarkov.Server.Core.Servers.Http.RequestLogger')"
}
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"formatter": "SPTarkov.Server.Logger.FileFormatter::Default, SPTarkov.Server",
"path": "./user/logs/requests/requests.txt",
"rollingInterval": "Day",
"fileSizeLimitBytes": "20971520",
"rollOnFileSizeLimit": true
}
}
]
}
}
},
{
"Name": "Logger",
"Args": {
+6
View File
@@ -26,6 +26,12 @@
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "StartsWith(SourceContext, 'SPTarkov.Server.Core.Servers.Http.RequestLogger')"
}
},
{
"Name": "ByExcluding",
"Args": {