* Add admin logging, models, migrations * Add logging damage changes * Add Log admin flag, LogFilter, Logs admin menu tab, message Refactor admin logging API * Change admin log get method names * Fix the name again * Minute amount of reorganization * Reset Postgres db snapshot * Reset Sqlite db snapshot * Make AdminLog have a composite primary key of round, id * Minute cleanup * Change admin system to do a type check instead of index check * Make admin logs use C# 10 interpolated string handlers * Implement UI on its own window Custom controls Searching Add admin log converters * Implement limits into the query * Change logs to be put into an OutputPanel instead for text wrapping * Add log <-> player m2m relationship back * UI improvements, make text wrap, add separators * Remove entity prefix from damaged log * Add explicit m2m model, fix any players filter * Add debug command to test bulk adding logs * Admin logs now just kinda go * Add histogram for database update time * Make admin log system update run every 5 seconds * Add a cap to the log queue and a metric for how many times it has been reached * Add metric for logs sent in a round * Make cvars out of admin logs queue send delay and cap * Merge fixes * Reset some changes * Add test for adding and getting a single log * Add tests for bulk adding logs * Add test for querying logs * Add CallerArgumentExpression to LogStringHandler methods and test * Improve UI, fix SQLite, add searching by round * Add entities to admin logs * Move distinct after orderby * Add migrations * ef core eat my ass * Add cvar for client logs batch size * Sort logs from newest to oldest by default * Merge fixes * Reorganize tests and add one for date ordering * Add note to log types to not change their numeric values * Add impacts to logs, better UI filtering * Make log add callable from shared for convenience * Get current round id directly from game ticker * Revert namespace change for DamageableSystem
111 lines
3.4 KiB
C#
111 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace Content.Shared.Administration.Logs;
|
|
|
|
[InterpolatedStringHandler]
|
|
public ref struct LogStringHandler
|
|
{
|
|
private DefaultInterpolatedStringHandler _handler;
|
|
public readonly Dictionary<string, object?> Values;
|
|
|
|
public LogStringHandler(int literalLength, int formattedCount)
|
|
{
|
|
_handler = new DefaultInterpolatedStringHandler(literalLength, formattedCount);
|
|
Values = new Dictionary<string, object?>();
|
|
}
|
|
|
|
public LogStringHandler(int literalLength, int formattedCount, IFormatProvider? provider)
|
|
{
|
|
_handler = new DefaultInterpolatedStringHandler(literalLength, formattedCount, provider);
|
|
Values = new Dictionary<string, object?>();
|
|
}
|
|
|
|
public LogStringHandler(int literalLength, int formattedCount, IFormatProvider? provider, Span<char> initialBuffer)
|
|
{
|
|
_handler = new DefaultInterpolatedStringHandler(literalLength, formattedCount, provider, initialBuffer);
|
|
Values = new Dictionary<string, object?>();
|
|
}
|
|
|
|
private void AddFormat<T>(string? format, T value, string? argument = null)
|
|
{
|
|
if (format == null)
|
|
{
|
|
if (argument == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
format = argument[0] == '@' ? argument[1..] : argument;
|
|
}
|
|
|
|
Values.Add(format, value);
|
|
}
|
|
|
|
public void AppendLiteral(string value)
|
|
{
|
|
_handler.AppendLiteral(value);
|
|
}
|
|
|
|
public void AppendFormatted<T>(T value, [CallerArgumentExpression("value")] string? argument = null)
|
|
{
|
|
AddFormat(null, value, argument);
|
|
_handler.AppendFormatted(value);
|
|
}
|
|
|
|
public void AppendFormatted<T>(T value, string? format, [CallerArgumentExpression("value")] string? argument = null)
|
|
{
|
|
AddFormat(format, value, argument);
|
|
_handler.AppendFormatted(value, format);
|
|
}
|
|
|
|
public void AppendFormatted<T>(T value, int alignment, [CallerArgumentExpression("value")] string? argument = null)
|
|
{
|
|
AddFormat(null, value, argument);
|
|
_handler.AppendFormatted(value, alignment);
|
|
}
|
|
|
|
public void AppendFormatted<T>(T value, int alignment, string? format, [CallerArgumentExpression("value")] string? argument = null)
|
|
{
|
|
AddFormat(format, value, argument);
|
|
_handler.AppendFormatted(value, alignment, format);
|
|
}
|
|
|
|
public void AppendFormatted(ReadOnlySpan<char> value)
|
|
{
|
|
_handler.AppendFormatted(value);
|
|
}
|
|
|
|
// ReSharper disable once MethodOverloadWithOptionalParameter
|
|
public void AppendFormatted(ReadOnlySpan<char> value, int alignment = 0, string? format = null)
|
|
{
|
|
AddFormat(format, value.ToString());
|
|
_handler.AppendFormatted(value, alignment, format);
|
|
}
|
|
|
|
public void AppendFormatted(string? value)
|
|
{
|
|
_handler.AppendFormatted(value);
|
|
}
|
|
|
|
// ReSharper disable once MethodOverloadWithOptionalParameter
|
|
public void AppendFormatted(string? value, int alignment = 0, string? format = null)
|
|
{
|
|
AddFormat(format, value);
|
|
_handler.AppendFormatted(value, alignment, format);
|
|
}
|
|
|
|
public void AppendFormatted(object? value, int alignment = 0, string? format = null)
|
|
{
|
|
AddFormat(null, value, format);
|
|
_handler.AppendFormatted(value, alignment, format);
|
|
}
|
|
|
|
public string ToStringAndClear()
|
|
{
|
|
Values.Clear();
|
|
return _handler.ToStringAndClear();
|
|
}
|
|
}
|