Various allocation & GC improvements
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
"profileSaveIntervalSeconds": 60,
|
||||
"sptFriendNickname": "SPT",
|
||||
"allowProfileWipe": true,
|
||||
"enableNoGCRegions": true,
|
||||
"enableNoGCRegions": false,
|
||||
"noGCRegionMaxMemoryGB": 4,
|
||||
"noGCRegionMaxLOHMemoryGB": 3,
|
||||
"bsgLogging": {
|
||||
|
||||
@@ -8,19 +8,32 @@ public abstract class BaseLogHandler : ILogHandler
|
||||
|
||||
protected string FormatMessage(string processedMessage, SptLogMessage message, BaseSptLoggerReference reference)
|
||||
{
|
||||
var formattedMessage = reference
|
||||
.Format.Replace("%date%", message.LogTime.ToString("yyyy-MM-dd"))
|
||||
.Replace("%time%", message.LogTime.ToString("HH:mm:ss.fff"))
|
||||
.Replace("%message%", processedMessage)
|
||||
.Replace("%loggerShort%", message.Logger.Split('.').Last())
|
||||
.Replace("%logger%", message.Logger)
|
||||
.Replace("%tid%", message.threadId.ToString())
|
||||
.Replace("%tname%", message.threadName)
|
||||
.Replace("%level%", Enum.GetName(message.LogLevel));
|
||||
var format = reference.GetCompiledFormat();
|
||||
|
||||
var formattedMessage = string.Format(
|
||||
null,
|
||||
format,
|
||||
message.LogTime.ToString("yyyy-MM-dd"),
|
||||
message.LogTime.ToString("HH:mm:ss.fff"),
|
||||
processedMessage,
|
||||
GetLoggerShortName(message.Logger),
|
||||
message.Logger,
|
||||
message.threadId,
|
||||
message.threadName,
|
||||
message.LogLevel.ToString()
|
||||
);
|
||||
|
||||
if (message.Exception != null)
|
||||
{
|
||||
formattedMessage += $"\n{message.Exception.Message}\n{message.Exception.StackTrace}";
|
||||
return string.Concat(formattedMessage, "\n", message.Exception.Message, "\n", message.Exception.StackTrace);
|
||||
}
|
||||
|
||||
return formattedMessage;
|
||||
}
|
||||
|
||||
protected string GetLoggerShortName(string logger)
|
||||
{
|
||||
var lastDotIndex = logger.AsSpan().LastIndexOf('.');
|
||||
return lastDotIndex >= 0 ? logger.Substring(lastDotIndex + 1) : logger;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class SptLogger<T> : ISptLogger<T>
|
||||
|
||||
private const string ConfigurationPath = "./sptLogger.json";
|
||||
private const string ConfigurationPathDev = "./sptLogger.Development.json";
|
||||
private SptLoggerConfiguration _config;
|
||||
private static SptLoggerConfiguration? _config = null;
|
||||
|
||||
public SptLogger(FileUtil fileUtil, JsonUtil jsonUtil, SptLoggerQueueManager loggerQueueManager)
|
||||
{
|
||||
@@ -27,13 +27,16 @@ public class SptLogger<T> : ISptLogger<T>
|
||||
_ => false,
|
||||
};
|
||||
|
||||
if (!ProgramStatics.DEBUG() || IsReleaseType)
|
||||
if (_config is null)
|
||||
{
|
||||
LoadConfig(fileUtil, jsonUtil, ConfigurationPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadConfig(fileUtil, jsonUtil, ConfigurationPathDev);
|
||||
if (!ProgramStatics.DEBUG() || IsReleaseType)
|
||||
{
|
||||
LoadConfig(fileUtil, jsonUtil, ConfigurationPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadConfig(fileUtil, jsonUtil, ConfigurationPathDev);
|
||||
}
|
||||
}
|
||||
|
||||
if (_config == null)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel;
|
||||
@@ -28,7 +29,31 @@ public abstract class BaseSptLoggerReference
|
||||
public LogLevel LogLevel { get; set; }
|
||||
|
||||
[JsonPropertyName("format")]
|
||||
public string Format { get; set; }
|
||||
public required string Format { get; set; }
|
||||
|
||||
private string? _cachedFormat;
|
||||
private CompositeFormat? _compiledFormat;
|
||||
|
||||
public virtual CompositeFormat GetCompiledFormat()
|
||||
{
|
||||
if (_cachedFormat != Format)
|
||||
{
|
||||
var convertedFormat = Format
|
||||
.Replace("%date%", "{0}")
|
||||
.Replace("%time%", "{1}")
|
||||
.Replace("%message%", "{2}")
|
||||
.Replace("%loggerShort%", "{3}")
|
||||
.Replace("%logger%", "{4}")
|
||||
.Replace("%tid%", "{5}")
|
||||
.Replace("%tname%", "{6}")
|
||||
.Replace("%level%", "{7}");
|
||||
|
||||
_compiledFormat = CompositeFormat.Parse(convertedFormat);
|
||||
_cachedFormat = Format;
|
||||
}
|
||||
|
||||
return _compiledFormat!;
|
||||
}
|
||||
}
|
||||
|
||||
public class SptLoggerFilter
|
||||
|
||||
Reference in New Issue
Block a user