Remove static Logger usages from BaseServer and BaseClient. (#4134)

This commit is contained in:
Vera Aguilera Puerto
2023-06-10 00:07:27 +02:00
committed by GitHub
parent 596b8e5538
commit 1959f6f328
2 changed files with 36 additions and 22 deletions

View File

@@ -46,7 +46,7 @@ namespace Robust.Server
/// <summary>
/// The master class that runs the rest of the engine.
/// </summary>
internal sealed class BaseServer : IBaseServerInternal
internal sealed class BaseServer : IBaseServerInternal, IPostInjectInit
{
private static readonly Gauge ServerUpTime = Metrics.CreateGauge(
"robust_server_uptime",
@@ -109,6 +109,7 @@ namespace Robust.Server
private Func<ILogHandler>? _logHandlerFactory;
private ILogHandler? _logHandler;
private IGameLoop _mainLoop = default!;
private ISawmill _logger = default!;
private bool _autoPause;
private string? _shutdownReason;
@@ -137,9 +138,9 @@ namespace Robust.Server
public void Shutdown(string? reason)
{
if (string.IsNullOrWhiteSpace(reason))
Logger.InfoS("srv", "Shutting down...");
_logger.Info("Shutting down...");
else
Logger.InfoS("srv", $"{reason}, shutting down...");
_logger.Info($"{reason}, shutting down...");
_shutdownReason = reason ?? "Shutting down";
@@ -278,7 +279,7 @@ namespace Robust.Server
catch (Exception e)
{
var port = _network.Port;
Logger.Fatal(
_logger.Fatal(
"Unable to setup networking manager. Check port {0} is not already in use and that all binding addresses are correct!\n{1}",
port, e);
return true;
@@ -305,7 +306,7 @@ namespace Robust.Server
if (!_modLoader.TryLoadModulesFrom(Options.AssemblyDirectory, Options.ContentModulePrefix))
{
Logger.Fatal("Errors while loading content assemblies.");
_logger.Fatal("Errors while loading content assemblies.");
return true;
}
@@ -443,6 +444,7 @@ namespace Robust.Server
return true;
}
var logger = _log.GetSawmill("loki");
var serverName = _config.GetCVar(CVars.LokiName);
var address = _config.GetCVar(CVars.LokiAddress);
var username = _config.GetCVar(CVars.LokiUsername);
@@ -450,13 +452,13 @@ namespace Robust.Server
if (string.IsNullOrWhiteSpace(serverName))
{
Logger.FatalS("loki", "Misconfiguration: Server name is not specified/empty.");
logger.Fatal("Misconfiguration: Server name is not specified/empty.");
return false;
}
if (string.IsNullOrWhiteSpace(address))
{
Logger.FatalS("loki", "Misconfiguration: Loki address is not specified/empty.");
logger.Fatal("Misconfiguration: Loki address is not specified/empty.");
return false;
}
@@ -469,7 +471,7 @@ namespace Robust.Server
{
if (string.IsNullOrWhiteSpace(password))
{
Logger.FatalS("loki", "Misconfiguration: Loki password is not specified/empty but username is.");
logger.Fatal("Misconfiguration: Loki password is not specified/empty but username is.");
return false;
}
@@ -479,7 +481,7 @@ namespace Robust.Server
cfg.LogLabelProvider = new LogLabelProvider(serverName);
Logger.DebugS("loki", "Loki enabled for server {ServerName} loki address {LokiAddress}.", serverName,
logger.Debug("Loki enabled for server {ServerName} loki address {LokiAddress}.", serverName,
address);
var handler = new LokiLogHandler(cfg);
@@ -546,7 +548,7 @@ namespace Robust.Server
// Don't start the main loop. This only works if a reason is passed to Shutdown(...)
if (_shutdownReason != null)
{
Logger.Fatal("Shutdown has been requested before the main loop has been started, complying.");
_logger.Fatal("Shutdown has been requested before the main loop has been started, complying.");
}
else _mainLoop.Run();
@@ -569,16 +571,16 @@ namespace Robust.Server
var b = (byte) i;
_time.TickRate = b;
Logger.InfoS("game", $"Tickrate changed to: {b} on tick {_time.CurTick}");
_logger.Info($"Tickrate changed to: {b} on tick {_time.CurTick}");
});
var startOffset = TimeSpan.FromSeconds(_config.GetCVar(CVars.NetTimeStartOffset));
_time.TimeBase = (startOffset, GameTick.First);
_time.TickRate = (byte) _config.GetCVar(CVars.NetTickrate);
Logger.InfoS("srv", $"Name: {ServerName}");
Logger.InfoS("srv", $"TickRate: {_time.TickRate}({_time.TickPeriod.TotalMilliseconds:0.00}ms)");
Logger.InfoS("srv", $"Max players: {MaxPlayers}");
_logger.Info($"Name: {ServerName}");
_logger.Info($"TickRate: {_time.TickRate}({_time.TickPeriod.TotalMilliseconds:0.00}ms)");
_logger.Info($"Max players: {MaxPlayers}");
_config.OnValueChanged(CVars.GameAutoPauseEmpty, UpdateAutoPause, true);
}
@@ -590,13 +592,13 @@ namespace Robust.Server
{
if (!_time.Paused && CheckIfShouldAutoPause())
{
Logger.DebugS("srv", "game.auto_pause_empty changed, pausing");
_logger.Debug("game.auto_pause_empty changed, pausing");
_time.Paused = true;
}
}
else if (_time.Paused)
{
Logger.DebugS("srv", "game.auto_pause_empty changed, unpausing");
_logger.Debug("game.auto_pause_empty changed, unpausing");
_time.Paused = false;
}
}
@@ -608,13 +610,13 @@ namespace Robust.Server
if (e.NewStatus == SessionStatus.Connected && _time.Paused)
{
Logger.DebugS("srv", "Client connecting, unpausing automatically.");
_logger.Debug("Client connecting, unpausing automatically.");
_time.Paused = false;
}
if (e.NewStatus == SessionStatus.Disconnected && CheckIfShouldAutoPause())
{
Logger.DebugS("srv", "Last client disconnected, pausing automatically.");
_logger.Debug("Last client disconnected, pausing automatically.");
_time.Paused = true;
}
}
@@ -724,5 +726,10 @@ namespace Robust.Server
_modLoader.BroadcastUpdate(ModUpdateLevel.FramePostEngine, frameEventArgs);
}
void IPostInjectInit.PostInject()
{
_logger = _log.GetSawmill("srv");
}
}
}