Implemented LogWithColor along side module changes, newtonsoft will always send a string
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -9,5 +9,6 @@ public enum LogBackgroundColor
|
||||
Blue = 44,
|
||||
Magenta = 45,
|
||||
Cyan = 46,
|
||||
White = 47
|
||||
White = 47,
|
||||
Default = 49
|
||||
}
|
||||
|
||||
@@ -9,5 +9,6 @@ public enum LogTextColor
|
||||
Blue = 34,
|
||||
Magenta = 35,
|
||||
Cyan = 36,
|
||||
White = 37
|
||||
White = 37,
|
||||
Gray = 90,
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -11,5 +11,3 @@ public enum LogLevel
|
||||
Debug,
|
||||
Trace
|
||||
}
|
||||
|
||||
// TODO: needs to be moved to enums namespace
|
||||
|
||||
@@ -5,8 +5,6 @@ namespace SPTarkov.Server.Core.Models.Utils;
|
||||
|
||||
public interface ISptLogger<T>
|
||||
{
|
||||
// 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);
|
||||
|
||||
@@ -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<EquipmentSlots>(),
|
||||
new EftEnumConverter<BuffType>(),
|
||||
new EftEnumConverter<BodyPartColliderType>(),
|
||||
|
||||
new EftEnumConverter<SPTarkov.Server.Core.Models.Spt.Logging.LogLevel>(),
|
||||
new EftEnumConverter<LogTextColor>(),
|
||||
new EftEnumConverter<LogBackgroundColor>(),
|
||||
|
||||
new EftListEnumConverter<EquipmentSlots>(),
|
||||
new EftListEnumConverter<PlayerSide>(),
|
||||
new EftListEnumConverter<DamageType>(),
|
||||
@@ -65,7 +71,6 @@ public class JsonUtil
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Convert JSON into an object
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user