Unify Content's EntitySystem logging (#26216)

Use Log with generated sawmill name rather than explicitly named one for all non rule-based Content EntitySystems.
This commit is contained in:
LordCarve
2024-03-17 21:30:27 +01:00
committed by GitHub
parent 4357b9ef08
commit eeaea6c25b
13 changed files with 43 additions and 82 deletions

View File

@@ -31,12 +31,10 @@ namespace Content.Server.Chemistry.EntitySystems
private const float ReactTime = 0.125f;
private ISawmill _sawmill = default!;
public override void Initialize()
{
base.Initialize();
_sawmill = Logger.GetSawmill("vapor");
SubscribeLocalEvent<VaporComponent, StartCollideEvent>(HandleCollide);
}
@@ -128,7 +126,7 @@ namespace Content.Server.Chemistry.EntitySystems
if (reaction > reagentQuantity.Quantity)
{
_sawmill.Error($"Tried to tile react more than we have for reagent {reagentQuantity}. Found {reaction} and we only have {reagentQuantity.Quantity}");
Log.Error($"Tried to tile react more than we have for reagent {reagentQuantity}. Found {reaction} and we only have {reagentQuantity.Quantity}");
reaction = reagentQuantity.Quantity;
}

View File

@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using Content.Server.DeviceNetwork.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.DeviceNetwork.Components;
@@ -12,8 +12,6 @@ namespace Content.Server.DeviceNetwork.Systems;
[UsedImplicitly]
public sealed class DeviceListSystem : SharedDeviceListSystem
{
private ISawmill _sawmill = default!;
[Dependency] private readonly NetworkConfiguratorSystem _configurator = default!;
public override void Initialize()
@@ -23,7 +21,6 @@ public sealed class DeviceListSystem : SharedDeviceListSystem
SubscribeLocalEvent<DeviceListComponent, BeforeBroadcastAttemptEvent>(OnBeforeBroadcast);
SubscribeLocalEvent<DeviceListComponent, BeforePacketSentEvent>(OnBeforePacketSent);
SubscribeLocalEvent<BeforeSaveEvent>(OnMapSave);
_sawmill = Logger.GetSawmill("devicelist");
}
private void OnShutdown(EntityUid uid, DeviceListComponent component, ComponentShutdown args)
@@ -154,7 +151,7 @@ public sealed class DeviceListSystem : SharedDeviceListSystem
// TODO full game saves.
// when full saves are supported, this should instead add data to the BeforeSaveEvent informing the
// saving system that this map (or null-space entity) also needs to be included in the save.
_sawmill.Error(
Log.Error(
$"Saving a device list ({ToPrettyString(uid)}) that has a reference to an entity on another map ({ToPrettyString(ent)}). Removing entity from list.");
}

View File

@@ -28,14 +28,10 @@ namespace Content.Server.Forensics
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
private ISawmill _sawmill = default!;
public override void Initialize()
{
base.Initialize();
_sawmill = Logger.GetSawmill("forensics.scanner");
SubscribeLocalEvent<ForensicScannerComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<ForensicScannerComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
SubscribeLocalEvent<ForensicScannerComponent, BeforeActivatableUIOpenEvent>(OnBeforeActivatableUIOpen);
@@ -57,7 +53,7 @@ namespace Content.Server.Forensics
component.PrintReadyAt);
if (!_uiSystem.TrySetUiState(uid, ForensicScannerUiKey.Key, state))
_sawmill.Warning($"{ToPrettyString(uid)} was unable to set UI state.");
Log.Warning($"{ToPrettyString(uid)} was unable to set UI state.");
}
private void OnDoAfter(EntityUid uid, ForensicScannerComponent component, DoAfterEvent args)
@@ -180,7 +176,7 @@ namespace Content.Server.Forensics
{
if (!args.Session.AttachedEntity.HasValue)
{
_sawmill.Warning($"{ToPrettyString(uid)} got OnPrint without Session.AttachedEntity");
Log.Warning($"{ToPrettyString(uid)} got OnPrint without Session.AttachedEntity");
return;
}
@@ -200,7 +196,7 @@ namespace Content.Server.Forensics
if (!HasComp<PaperComponent>(printed))
{
_sawmill.Error("Printed paper did not have PaperComponent.");
Log.Error("Printed paper did not have PaperComponent.");
return;
}

View File

@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.CCVar;
@@ -32,7 +32,6 @@ public sealed class MappingSystem : EntitySystem
/// <returns></returns>
private Dictionary<MapId, (TimeSpan next, string fileName)> _currentlyAutosaving = new();
private ISawmill _sawmill = default!;
private bool _autosaveEnabled;
public override void Initialize()
@@ -44,7 +43,6 @@ public sealed class MappingSystem : EntitySystem
"autosave <map> <path if enabling>",
ToggleAutosaveCommand);
_sawmill = Logger.GetSawmill("autosave");
Subs.CVar(_cfg, CCVars.AutosaveEnabled, SetAutosaveEnabled, true);
}
@@ -69,7 +67,7 @@ public sealed class MappingSystem : EntitySystem
if (!_mapManager.MapExists(map) || _mapManager.IsMapInitialized(map))
{
_sawmill.Warning($"Can't autosave map {map}; it doesn't exist, or is initialized. Removing from autosave.");
Log.Warning($"Can't autosave map {map}; it doesn't exist, or is initialized. Removing from autosave.");
_currentlyAutosaving.Remove(map);
return;
}
@@ -79,7 +77,7 @@ public sealed class MappingSystem : EntitySystem
var path = Path.Combine(saveDir, $"{DateTime.Now.ToString("yyyy-M-dd_HH.mm.ss")}-AUTO.yml");
_currentlyAutosaving[map] = (CalculateNextTime(), name);
_sawmill.Info($"Autosaving map {name} ({map}) to {path}. Next save in {ReadableTimeLeft(map)} seconds.");
Log.Info($"Autosaving map {name} ({map}) to {path}. Next save in {ReadableTimeLeft(map)} seconds.");
_map.SaveMap(map, path);
}
}
@@ -105,17 +103,17 @@ public sealed class MappingSystem : EntitySystem
{
if (!_mapManager.MapExists(map) || _mapManager.IsMapInitialized(map))
{
_sawmill.Warning("Tried to enable autosaving on non-existant or already initialized map!");
Log.Warning("Tried to enable autosaving on non-existant or already initialized map!");
_currentlyAutosaving.Remove(map);
return;
}
_sawmill.Info($"Started autosaving map {path} ({map}). Next save in {ReadableTimeLeft(map)} seconds.");
Log.Info($"Started autosaving map {path} ({map}). Next save in {ReadableTimeLeft(map)} seconds.");
}
else
{
_currentlyAutosaving.Remove(map);
_sawmill.Info($"Stopped autosaving on map {map}");
Log.Info($"Stopped autosaving on map {map}");
}
}

View File

@@ -39,15 +39,11 @@ public sealed partial class MechSystem : SharedMechSystem
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
private ISawmill _sawmill = default!;
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
_sawmill = Logger.GetSawmill("mech");
SubscribeLocalEvent<MechComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<MechComponent, EntInsertedIntoContainerMessage>(OnInsertBattery);
SubscribeLocalEvent<MechComponent, MapInitEvent>(OnMapInit);
@@ -343,7 +339,7 @@ public sealed partial class MechSystem : SharedMechSystem
_battery.SetCharge(battery!.Value, batteryComp.CurrentCharge + delta.Float(), batteryComp);
if (batteryComp.CurrentCharge != component.Energy) //if there's a discrepency, we have to resync them
{
_sawmill.Debug($"Battery charge was not equal to mech charge. Battery {batteryComp.CurrentCharge}. Mech {component.Energy}");
Log.Debug($"Battery charge was not equal to mech charge. Battery {batteryComp.CurrentCharge}. Mech {component.Energy}");
component.Energy = batteryComp.CurrentCharge;
Dirty(component);
}

View File

@@ -18,12 +18,10 @@ public sealed class LagCompensationSystem : EntitySystem
// Max ping I've had is 350ms from aus to spain.
public static readonly TimeSpan BufferTime = TimeSpan.FromMilliseconds(750);
private ISawmill _sawmill = Logger.GetSawmill("lagcomp");
public override void Initialize()
{
base.Initialize();
_sawmill.Level = LogLevel.Info;
Log.Level = LogLevel.Info;
SubscribeLocalEvent<LagCompensationComponent, MoveEvent>(OnLagMove);
}
@@ -87,13 +85,13 @@ public sealed class LagCompensationSystem : EntitySystem
if (coordinates == default)
{
_sawmill.Debug($"No long comp coords found, using {xform.Coordinates}");
Log.Debug($"No long comp coords found, using {xform.Coordinates}");
coordinates = xform.Coordinates;
angle = xform.LocalRotation;
}
else
{
_sawmill.Debug($"Actual coords is {xform.Coordinates} and got {coordinates}");
Log.Debug($"Actual coords is {xform.Coordinates} and got {coordinates}");
}
return (coordinates, angle);

View File

@@ -14,8 +14,6 @@ public sealed partial class NpcFactionSystem : EntitySystem
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
private ISawmill _sawmill = default!;
/// <summary>
/// To avoid prototype mutability we store an intermediary data class that gets used instead.
/// </summary>
@@ -24,7 +22,7 @@ public sealed partial class NpcFactionSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
_sawmill = Logger.GetSawmill("faction");
SubscribeLocalEvent<NpcFactionMemberComponent, ComponentStartup>(OnFactionStartup);
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnProtoReload);
@@ -69,7 +67,7 @@ public sealed partial class NpcFactionSystem : EntitySystem
{
if (!_protoManager.HasIndex<NpcFactionPrototype>(faction))
{
_sawmill.Error($"Unable to find faction {faction}");
Log.Error($"Unable to find faction {faction}");
return;
}
@@ -90,7 +88,7 @@ public sealed partial class NpcFactionSystem : EntitySystem
{
if (!_protoManager.HasIndex<NpcFactionPrototype>(faction))
{
_sawmill.Error($"Unable to find faction {faction}");
Log.Error($"Unable to find faction {faction}");
return;
}
@@ -213,13 +211,13 @@ public sealed partial class NpcFactionSystem : EntitySystem
{
if (!_factions.TryGetValue(source, out var sourceFaction))
{
_sawmill.Error($"Unable to find faction {source}");
Log.Error($"Unable to find faction {source}");
return;
}
if (!_factions.ContainsKey(target))
{
_sawmill.Error($"Unable to find faction {target}");
Log.Error($"Unable to find faction {target}");
return;
}
@@ -255,13 +253,13 @@ public sealed partial class NpcFactionSystem : EntitySystem
{
if (!_factions.TryGetValue(source, out var sourceFaction))
{
_sawmill.Error($"Unable to find faction {source}");
Log.Error($"Unable to find faction {source}");
return;
}
if (!_factions.ContainsKey(target))
{
_sawmill.Error($"Unable to find faction {target}");
Log.Error($"Unable to find faction {target}");
return;
}

View File

@@ -64,8 +64,6 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
private ISawmill _sawmill = default!;
private const float ShuttleSpawnBuffer = 1f;
private bool _emergencyShuttleEnabled;
@@ -75,7 +73,6 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
public override void Initialize()
{
_sawmill = Logger.GetSawmill("shuttle.emergency");
_emergencyShuttleEnabled = _configManager.GetCVar(CCVars.EmergencyShuttleEnabled);
// Don't immediately invoke as roundstart will just handle it.
Subs.CVar(_configManager, CCVars.EmergencyShuttleEnabled, SetEmergencyShuttleEnabled);
@@ -391,7 +388,7 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
{
if (component.MapEntity != null || component.Entity != null)
{
_sawmill.Warning("Attempted to re-add an existing centcomm map.");
Log.Warning("Attempted to re-add an existing centcomm map.");
return;
}
@@ -416,7 +413,7 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
if (string.IsNullOrEmpty(component.Map.ToString()))
{
_sawmill.Warning("No CentComm map found, skipping setup.");
Log.Warning("No CentComm map found, skipping setup.");
return;
}
@@ -491,7 +488,7 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
if (shuttle == null)
{
_sawmill.Error($"Unable to spawn emergency shuttle {shuttlePath} for {ToPrettyString(uid)}");
Log.Error($"Unable to spawn emergency shuttle {shuttlePath} for {ToPrettyString(uid)}");
return;
}

View File

@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using Content.Server.GameTicking;
using Content.Server.StationEvents.Components;
using Content.Shared.CCVar;
@@ -17,8 +17,6 @@ public sealed class EventManagerSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] public readonly GameTicker GameTicker = default!;
private ISawmill _sawmill = default!;
public bool EventsEnabled { get; private set; }
private void SetEnabled(bool value) => EventsEnabled = value;
@@ -26,8 +24,6 @@ public sealed class EventManagerSystem : EntitySystem
{
base.Initialize();
_sawmill = Logger.GetSawmill("events");
Subs.CVar(_configurationManager, CCVars.EventsEnabled, SetEnabled, true);
}
@@ -41,13 +37,13 @@ public sealed class EventManagerSystem : EntitySystem
if (randomEvent == null)
{
var errStr = Loc.GetString("station-event-system-run-random-event-no-valid-events");
_sawmill.Error(errStr);
Log.Error(errStr);
return errStr;
}
var ent = GameTicker.AddGameRule(randomEvent);
var str = Loc.GetString("station-event-system-run-event",("eventName", ToPrettyString(ent)));
_sawmill.Info(str);
Log.Info(str);
return str;
}
@@ -57,7 +53,7 @@ public sealed class EventManagerSystem : EntitySystem
public string? PickRandomEvent()
{
var availableEvents = AvailableEvents();
_sawmill.Info($"Picking from {availableEvents.Count} total available events");
Log.Info($"Picking from {availableEvents.Count} total available events");
return FindEvent(availableEvents);
}
@@ -69,7 +65,7 @@ public sealed class EventManagerSystem : EntitySystem
{
if (availableEvents.Count == 0)
{
_sawmill.Warning("No events were available to run!");
Log.Warning("No events were available to run!");
return null;
}
@@ -92,7 +88,7 @@ public sealed class EventManagerSystem : EntitySystem
}
}
_sawmill.Error("Event was not found after weighted pick process!");
Log.Error("Event was not found after weighted pick process!");
return null;
}
@@ -116,7 +112,7 @@ public sealed class EventManagerSystem : EntitySystem
{
if (CanRun(proto, stationEvent, playerCount, currentTime))
{
_sawmill.Debug($"Adding event {proto.ID} to possibilities");
Log.Debug($"Adding event {proto.ID} to possibilities");
result.Add(proto, stationEvent);
}
}

View File

@@ -41,13 +41,10 @@ namespace Content.Server.VendingMachines
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AdvertiseSystem _advertise = default!;
private ISawmill _sawmill = default!;
public override void Initialize()
{
base.Initialize();
_sawmill = Logger.GetSawmill("vending");
SubscribeLocalEvent<VendingMachineComponent, MapInitEvent>(OnComponentMapInit);
SubscribeLocalEvent<VendingMachineComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<VendingMachineComponent, BreakageEventArgs>(OnBreak);
@@ -86,7 +83,7 @@ namespace Content.Server.VendingMachines
{
if (!PrototypeManager.TryIndex<EntityPrototype>(entry.ID, out var proto))
{
_sawmill.Error($"Unable to find entity prototype {entry.ID} on {ToPrettyString(uid)} vending.");
Log.Error($"Unable to find entity prototype {entry.ID} on {ToPrettyString(uid)} vending.");
continue;
}
@@ -193,7 +190,7 @@ namespace Content.Server.VendingMachines
if (!TryComp<VendingMachineRestockComponent>(args.Args.Used, out var restockComponent))
{
_sawmill.Error($"{ToPrettyString(args.Args.User)} tried to restock {ToPrettyString(uid)} with {ToPrettyString(args.Args.Used.Value)} which did not have a VendingMachineRestockComponent.");
Log.Error($"{ToPrettyString(args.Args.User)} tried to restock {ToPrettyString(uid)} with {ToPrettyString(args.Args.Used.Value)} which did not have a VendingMachineRestockComponent.");
return;
}

View File

@@ -35,8 +35,6 @@ public abstract class SharedAnomalySystem : EntitySystem
[Dependency] protected readonly SharedPopupSystem Popup = default!;
[Dependency] private readonly IRobustRandom _random = default!;
private ISawmill _sawmill = default!;
public override void Initialize()
{
base.Initialize();
@@ -45,8 +43,6 @@ public abstract class SharedAnomalySystem : EntitySystem
SubscribeLocalEvent<AnomalyComponent, AttackedEvent>(OnAttacked);
SubscribeLocalEvent<AnomalyComponent, MeleeThrowOnHitStartEvent>(OnAnomalyThrowStart);
SubscribeLocalEvent<AnomalyComponent, MeleeThrowOnHitEndEvent>(OnAnomalyThrowEnd);
_sawmill = Logger.GetSawmill("anomaly");
}
private void OnInteractHand(EntityUid uid, AnomalyComponent component, InteractHandEvent args)
@@ -98,7 +94,7 @@ public abstract class SharedAnomalySystem : EntitySystem
component.NextPulseTime = Timing.CurTime + GetPulseLength(component) * variation;
if (_net.IsServer)
_sawmill.Info($"Performing anomaly pulse. Entity: {ToPrettyString(uid)}");
Log.Info($"Performing anomaly pulse. Entity: {ToPrettyString(uid)}");
// if we are above the growth threshold, then grow before the pulse
if (component.Stability > component.GrowthThreshold)
@@ -135,7 +131,7 @@ public abstract class SharedAnomalySystem : EntitySystem
AdminLog.Add(LogType.Anomaly, LogImpact.Extreme, $"Anomaly {ToPrettyString(uid)} began to go supercritical.");
if (_net.IsServer)
_sawmill.Info($"Anomaly is going supercritical. Entity: {ToPrettyString(uid)}");
Log.Info($"Anomaly is going supercritical. Entity: {ToPrettyString(uid)}");
var super = AddComp<AnomalySupercriticalComponent>(uid);
super.EndTime = Timing.CurTime + super.SupercriticalDuration;
@@ -161,7 +157,7 @@ public abstract class SharedAnomalySystem : EntitySystem
Audio.PlayPvs(component.SupercriticalSound, uid);
if (_net.IsServer)
_sawmill.Info($"Raising supercritical event. Entity: {ToPrettyString(uid)}");
Log.Info($"Raising supercritical event. Entity: {ToPrettyString(uid)}");
var ev = new AnomalySupercriticalEvent(uid);
RaiseLocalEvent(uid, ref ev, true);
@@ -179,7 +175,7 @@ public abstract class SharedAnomalySystem : EntitySystem
{
// Logging before resolve, in case the anomaly has deleted itself.
if (_net.IsServer)
_sawmill.Info($"Ending anomaly. Entity: {ToPrettyString(uid)}");
Log.Info($"Ending anomaly. Entity: {ToPrettyString(uid)}");
AdminLog.Add(LogType.Anomaly, supercritical ? LogImpact.High : LogImpact.Low,
$"Anomaly {ToPrettyString(uid)} {(supercritical ? "went supercritical" : "decayed")}.");

View File

@@ -13,7 +13,6 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
private ISawmill _sawmill = default!;
public const string InvokedPort = "link_port";
@@ -25,7 +24,6 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
SubscribeLocalEvent<DeviceLinkSinkComponent, ComponentStartup>(OnSinkStartup);
SubscribeLocalEvent<DeviceLinkSourceComponent, ComponentRemove>(OnSourceRemoved);
SubscribeLocalEvent<DeviceLinkSinkComponent, ComponentRemove>(OnSinkRemoved);
_sawmill = Logger.GetSawmill("devicelink");
}
#region Link Validation
@@ -386,12 +384,12 @@ public abstract class SharedDeviceLinkSystem : EntitySystem
if (sourceComponent == null)
{
_sawmill.Error($"Attempted to remove link between {ToPrettyString(sourceUid)} and {ToPrettyString(sinkUid)}, but the source component was missing.");
Log.Error($"Attempted to remove link between {ToPrettyString(sourceUid)} and {ToPrettyString(sinkUid)}, but the source component was missing.");
sinkComponent!.LinkedSources.Remove(sourceUid);
}
else
{
_sawmill.Error($"Attempted to remove link between {ToPrettyString(sourceUid)} and {ToPrettyString(sinkUid)}, but the sink component was missing.");
Log.Error($"Attempted to remove link between {ToPrettyString(sourceUid)} and {ToPrettyString(sinkUid)}, but the sink component was missing.");
sourceComponent.LinkedPorts.Remove(sourceUid);
}
}

View File

@@ -18,14 +18,10 @@ public sealed class ThirstSystem : EntitySystem
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly SharedJetpackSystem _jetpack = default!;
private ISawmill _sawmill = default!;
public override void Initialize()
{
base.Initialize();
_sawmill = Logger.GetSawmill("thirst");
SubscribeLocalEvent<ThirstComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
SubscribeLocalEvent<ThirstComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ThirstComponent, RejuvenateEvent>(OnRejuvenate);
@@ -156,7 +152,7 @@ public sealed class ThirstSystem : EntitySystem
return;
default:
_sawmill.Error($"No thirst threshold found for {component.CurrentThirstThreshold}");
Log.Error($"No thirst threshold found for {component.CurrentThirstThreshold}");
throw new ArgumentOutOfRangeException($"No thirst threshold found for {component.CurrentThirstThreshold}");
}
}