From 74f755af6134f605366feaffaef1e5aa1a3e5091 Mon Sep 17 00:00:00 2001 From: CWX Date: Wed, 16 Apr 2025 13:00:01 +0100 Subject: [PATCH] Implemented LogWithColor along side module changes, newtonsoft will always send a string --- .../Controllers/ClientLogController.cs | 9 +++------ .../Models/Logging/LogBackgroundColor.cs | 3 ++- .../Models/Logging/LogTextColor.cs | 3 ++- .../Models/Spt/Logging/ClientLogRequest.cs | 11 +++++++---- .../Models/Spt/Logging/LogLevel.cs | 2 -- .../SPTarkov.Server.Core/Models/Utils/ISptLogger.cs | 2 -- Libraries/SPTarkov.Server.Core/Utils/JsonUtil.cs | 7 ++++++- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Controllers/ClientLogController.cs b/Libraries/SPTarkov.Server.Core/Controllers/ClientLogController.cs index cd077a22..400e90a9 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/ClientLogController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/ClientLogController.cs @@ -1,6 +1,7 @@ using SPTarkov.Server.Core.Models.Spt.Logging; using SPTarkov.Server.Core.Models.Utils; using SPTarkov.Common.Annotations; +using SPTarkov.Server.Core.Models.Logging; using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel; namespace SPTarkov.Server.Core.Controllers; @@ -17,13 +18,9 @@ public class ClientLogController( public void ClientLog(ClientLogRequest logRequest) { var message = $"[{logRequest.Source}] {logRequest.Message}"; - /* TODO: what do we do with this? + var color = logRequest.Color ?? LogTextColor.White; var backgroundColor = logRequest.BackgroundColor ?? LogBackgroundColor.Default; - */ - - // Allow supporting either string or enum levels - // Required due to the C# modules serializing enums as their name switch (logRequest.Level) { @@ -38,7 +35,7 @@ public class ClientLogController( _logger.Info(message); break; case LogLevel.Custom: - _logger.Info(message /* TODO: , color.ToString(), backgroundColor.ToString()*/); + _logger.LogWithColor(message, color, backgroundColor, null); break; case LogLevel.Debug: _logger.Debug(message); diff --git a/Libraries/SPTarkov.Server.Core/Models/Logging/LogBackgroundColor.cs b/Libraries/SPTarkov.Server.Core/Models/Logging/LogBackgroundColor.cs index fa1b6f72..1e0829fe 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Logging/LogBackgroundColor.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Logging/LogBackgroundColor.cs @@ -9,5 +9,6 @@ public enum LogBackgroundColor Blue = 44, Magenta = 45, Cyan = 46, - White = 47 + White = 47, + Default = 49 } diff --git a/Libraries/SPTarkov.Server.Core/Models/Logging/LogTextColor.cs b/Libraries/SPTarkov.Server.Core/Models/Logging/LogTextColor.cs index 2659a8e0..1a1783f5 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Logging/LogTextColor.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Logging/LogTextColor.cs @@ -9,5 +9,6 @@ public enum LogTextColor Blue = 34, Magenta = 35, Cyan = 36, - White = 37 + White = 37, + Gray = 90, } diff --git a/Libraries/SPTarkov.Server.Core/Models/Spt/Logging/ClientLogRequest.cs b/Libraries/SPTarkov.Server.Core/Models/Spt/Logging/ClientLogRequest.cs index 32f963bc..d7810c6d 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Spt/Logging/ClientLogRequest.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Spt/Logging/ClientLogRequest.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using SPTarkov.Server.Core.Models.Logging; using SPTarkov.Server.Core.Models.Utils; namespace SPTarkov.Server.Core.Models.Spt.Logging; @@ -13,7 +14,7 @@ public record ClientLogRequest : IRequestData } [JsonPropertyName("Level")] - [JsonConverter(typeof(JsonStringEnumConverter))] // TODO: Fix in modules to send enumValue instead of string + [JsonConverter(typeof(JsonStringEnumConverter))] public LogLevel? Level { get; @@ -28,14 +29,16 @@ public record ClientLogRequest : IRequestData } [JsonPropertyName("Color")] - public string? Color + [JsonConverter(typeof(JsonStringEnumConverter))] + public LogTextColor? Color { get; set; - } // TODO: FIX THIS SHIT FOR COLOURS + } [JsonPropertyName("BackgroundColor")] - public string? BackgroundColor + [JsonConverter(typeof(JsonStringEnumConverter))] + public LogBackgroundColor? BackgroundColor { get; set; diff --git a/Libraries/SPTarkov.Server.Core/Models/Spt/Logging/LogLevel.cs b/Libraries/SPTarkov.Server.Core/Models/Spt/Logging/LogLevel.cs index 2c8a83c6..6be6a5ec 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Spt/Logging/LogLevel.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Spt/Logging/LogLevel.cs @@ -11,5 +11,3 @@ public enum LogLevel Debug, Trace } - -// TODO: needs to be moved to enums namespace diff --git a/Libraries/SPTarkov.Server.Core/Models/Utils/ISptLogger.cs b/Libraries/SPTarkov.Server.Core/Models/Utils/ISptLogger.cs index 4453e43e..e0b4b892 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Utils/ISptLogger.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Utils/ISptLogger.cs @@ -5,8 +5,6 @@ namespace SPTarkov.Server.Core.Models.Utils; public interface ISptLogger { - // TODO: Removing these methods for now, revisit in the future - // void Log(string data, LogTextColor? color, string? backgroundColor = null); void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null, Exception? ex = null); void Success(string data, Exception? ex = null); void Error(string data, Exception? ex = null); diff --git a/Libraries/SPTarkov.Server.Core/Utils/JsonUtil.cs b/Libraries/SPTarkov.Server.Core/Utils/JsonUtil.cs index 33d0da44..1c68ef02 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/JsonUtil.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/JsonUtil.cs @@ -9,6 +9,7 @@ using SPTarkov.Server.Core.Models.Spt.Dialog; using SPTarkov.Server.Core.Utils.Json.Converters; using SPTarkov.Common.Annotations; using SPTarkov.Server.Core.Models.Eft.Common; +using SPTarkov.Server.Core.Models.Logging; namespace SPTarkov.Server.Core.Utils; @@ -53,6 +54,11 @@ public class JsonUtil new EftEnumConverter(), new EftEnumConverter(), new EftEnumConverter(), + + new EftEnumConverter(), + new EftEnumConverter(), + new EftEnumConverter(), + new EftListEnumConverter(), new EftListEnumConverter(), new EftListEnumConverter(), @@ -65,7 +71,6 @@ public class JsonUtil WriteIndented = true }; - /// /// Convert JSON into an object ///