Skip to content

Commit

Permalink
Mirror: Obsolete Logger cleanup for EntitySystems (#132)
Browse files Browse the repository at this point in the history
## Mirror of PR #25941: [Obsolete `Logger` cleanup for
`EntitySystem`s](space-wizards/space-station-14#25941)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `aafe81512258b5a80776ada1f471b58e7507ca2d`

PR opened by <img
src="https://avatars.githubusercontent.com/u/27449516?v=4"
width="16"/><a href="https://github.com/LordCarve"> LordCarve</a> at
2024-03-09 12:19:14 UTC
PR merged by <img
src="https://avatars.githubusercontent.com/u/19864447?v=4"
width="16"/><a href="https://github.com/web-flow"> web-flow</a> at
2024-03-10 00:15:13 UTC

---

PR changed 25 files with 41 additions and 45 deletions.

The PR had the following labels:
- Status: Needs Review


---

<details open="true"><summary><h1>Original Body</h1></summary>

> <!-- Please read these guidelines before opening your PR:
https://docs.spacestation14.io/en/getting-started/pr-guideline -->
> <!-- The text between the arrows are comments - they will not be
visible on your PR. -->
> 
> ## About the PR
> <!-- What did you change in this PR? -->
> Changed almost all[^1] obsolete `Logger` calls in Content's
`EntitySystem`s to use `Log` instead. `Log` automatically selects the
system-specific `Sawmill`, so this isn't just a refactor - it makes logs
slightly more accurate (puts them in appropriate sawmill/context rather
than the root sawmill).
> 
> ## Why / Balance
> <!-- Why was it changed? Link any discussions or issues here. Please
discuss how this would affect game balance. -->
> Using `Logger` directly for logging is marked obsolete. Assumed this
is a desired change.
> 
> ## Technical details
> <!-- If this is a code change, summarize at high level how your new
code works. This makes it easier to review. -->
> This changes some log contexts, but generally in a desirable way:
> - For most, it put logs in `system.appropriate` `Sawmill` rather than
root.
> - For some that were forced into another `Sawmill` it changes it to a
more specific one, i.e. from `atmos` it becomes `system.gas_filter` or
`system.automatic_atmos` and `system.station` into
`system.station_jobs`.
> - For the rest it remains unchanged
> 
> **I assumed that all of the above was desirable because this seems to
be the standard convention** - I imagine that was the idea behind the
`Log` in all `EntitySystem`s coupled with `[Obsolete] Logger` methods -
**but if my assumptions are incorrect and/or there are exceptions,
please let me know and I will adjust.**
> 
> [^1]: There is only one `EntitySystem` that I didn't update -
`ExamineSystemShared`. That is because the `Logger` is in a `static`
method and refactoring that away causes a lot of cascading changes. May
do it as a separate PR to avoid overly diluting this one.
> 
> ## Media
> <!-- 
> PRs which make ingame changes (adding clothing, items, new features,
etc) are required to have media attached that showcase the changes.
> Small fixes/refactors are exempt.
> Any media may be used in SS14 progress reports, with clear credit
given.
> 
> If you're unsure whether your PR will require media, ask a maintainer.
> 
> Check the box below to confirm that you have in fact seen this (put an
X in the brackets, like [X]):
> -->
> 
> - [X] I have added screenshots/videos to this PR showcasing its
changes ingame, **or** this PR does not require an ingame showcase
> 
> ## Breaking changes
> <!--
> List any breaking changes, including namespace, public
class/method/field changes, prototype renames; and provide instructions
for fixing them. This will be pasted in #codebase-changes.
> -->
> Log output changes. `EntitySystem` logs now go to the expected
`Sawmill` for the system rather than hardcoded/root one.
> Any log analyzers anticipating these logs' context must be updated.


</details>

Co-authored-by: LordCarve <27449516+LordCarve@users.noreply.github.com>
  • Loading branch information
SimpleStation14 and LordCarve authored May 4, 2024
1 parent 080a041 commit b1e3b79
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Alerts/ClientAlertsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void LoadPrototypes()

AlertOrder = _prototypeManager.EnumeratePrototypes<AlertOrderPrototype>().FirstOrDefault();
if (AlertOrder == null)
Log.Error("alert", "no alertOrder prototype found, alerts will be in random order");
Log.Error("No alertOrder prototype found, alerts will be in random order");
}

public IReadOnlyDictionary<AlertKey, AlertState>? ActiveAlerts
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Clothing/ClientClothingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private void RenderEquipment(EntityUid equipee, EntityUid equipment, string slot
{
if (!revealedLayers.Add(key))
{
Logger.Warning($"Duplicate key for clothing visuals: {key}. Are multiple components attempting to modify the same layer? Equipment: {ToPrettyString(equipment)}");
Log.Warning($"Duplicate key for clothing visuals: {key}. Are multiple components attempting to modify the same layer? Equipment: {ToPrettyString(equipment)}");
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions Content.Client/IconSmoothing/IconSmoothSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private void CalculateNewSprite(EntityUid uid,

if (!spriteQuery.TryGetComponent(uid, out var sprite))
{
Logger.Error($"Encountered a icon-smoothing entity without a sprite: {ToPrettyString(uid)}");
Log.Error($"Encountered a icon-smoothing entity without a sprite: {ToPrettyString(uid)}");
RemCompDeferred(uid, smooth);
return;
}
Expand All @@ -242,7 +242,7 @@ private void CalculateNewSprite(EntityUid uid,
{
if (!_mapManager.TryGetGrid(xform.GridUid, out grid))
{
Logger.Error($"Failed to calculate IconSmoothComponent sprite in {uid} because grid {xform.GridUid} was missing.");
Log.Error($"Failed to calculate IconSmoothComponent sprite in {uid} because grid {xform.GridUid} was missing.");
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Info/InfoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<RulesMessage>(OnRulesReceived);
Logger.DebugS("info", "Requested server info.");
Log.Debug("Requested server info.");
RaiseNetworkEvent(new RequestRulesMessage());
}

private void OnRulesReceived(RulesMessage message, EntitySessionEventArgs eventArgs)
{
Logger.DebugS("info", "Received server rules.");
Log.Debug("Received server rules.");
Rules = message;
_rules.UpdateRules();
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Light/RgbLightControllerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void GetOriginalColors(EntityUid uid, RgbLightControllerComponent? rgb =
else
{
// admeme fuck-ups or bad yaml?
Logger.Warning($"RGB light attempted to use invalid sprite index {index} on entity {ToPrettyString(uid)}");
Log.Warning($"RGB light attempted to use invalid sprite index {index} on entity {ToPrettyString(uid)}");
rgb.Layers.Remove(index);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Sprite/RandomSpriteSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void UpdateSpriteComponentAppearance(EntityUid uid, RandomSpriteComponen
{
if (layer.Key is not { } strKey || !int.TryParse(strKey, out index))
{
Logger.Error($"Invalid key `{layer.Key}` for entity with random sprite {ToPrettyString(uid)}");
Log.Error($"Invalid key `{layer.Key}` for entity with random sprite {ToPrettyString(uid)}");
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Atmos/EntitySystems/AutomaticAtmosSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void OnTileChanged(ref TileChangedEvent ev)
if (physics.Mass / ShuttleSystem.TileMassMultiplier >= 7.0f)
{
AddComp<GridAtmosphereComponent>(ev.Entity);
Logger.InfoS("atmos", $"Giving grid {ev.Entity} GridAtmosphereComponent.");
Log.Info($"Giving grid {ev.Entity} GridAtmosphereComponent.");
}
// It's not super important to remove it should the grid become too small again.
// If explosions ever gain the ability to outright shatter grids, do rethink this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void OnSelectGasMessage(EntityUid uid, GasFilterComponent filter, GasFil
}
else
{
Logger.Warning("atmos", $"{ToPrettyString(uid)} received GasFilterSelectGasMessage with an invalid ID: {args.ID}");
Log.Warning($"{ToPrettyString(uid)} received GasFilterSelectGasMessage with an invalid ID: {args.ID}");
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public override void Update(float frameTime)
#endif
}

Logger.InfoS("Explosion", $"Processed {TilesPerTick - tilesRemaining} tiles in {Stopwatch.Elapsed.TotalMilliseconds}ms");
Log.Info($"Processed {TilesPerTick - tilesRemaining} tiles in {Stopwatch.Elapsed.TotalMilliseconds}ms");

// we have finished processing our tiles. Is there still an ongoing explosion?
if (_activeExplosion != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed partial class ExplosionSystem : EntitySystem

if (!_explosionTypes.TryGetValue(typeID, out var typeIndex))
{
Logger.Error("Attempted to spawn explosion using a prototype that was not defined during initialization. Explosion prototype hot-reload is not currently supported.");
Log.Error("Attempted to spawn explosion using a prototype that was not defined during initialization. Explosion prototype hot-reload is not currently supported.");
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Explosion/EntitySystems/ExplosionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public void QueueExplosion(MapCoordinates epicenter,

if (!_prototypeManager.TryIndex<ExplosionPrototype>(typeId, out var type))
{
Logger.Error($"Attempted to spawn unknown explosion prototype: {type}");
Log.Error($"Attempted to spawn unknown explosion prototype: {type}");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void OnTrigger(EntityUid uid, SmokeOnTriggerComponent comp, TriggerEvent
var ent = Spawn(comp.SmokePrototype, coords.SnapToGrid());
if (!TryComp<SmokeComponent>(ent, out var smoke))
{
Logger.Error($"Smoke prototype {comp.SmokePrototype} was missing SmokeComponent");
Log.Error($"Smoke prototype {comp.SmokePrototype} was missing SmokeComponent");
Del(ent);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public string GetAgeRepresentation(string species, int age)

if (speciesPrototype == null)
{
Logger.Error("Tried to get age representation of species that couldn't be indexed: " + species);
Log.Error("Tried to get age representation of species that couldn't be indexed: " + species);
return Loc.GetString("identity-age-young");
}

Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Info/InfoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override void Initialize()

private void OnRequestRules(RequestRulesMessage message, EntitySessionEventArgs eventArgs)
{
Log.Debug("info", "Client requested rules.");
Log.Debug("Client requested rules.");
var title = Loc.GetString(_cfg.GetCVar(CCVars.RulesHeader));
var path = _cfg.GetCVar(CCVars.RulesFile);
var rules = "Server could not read its rules.";
Expand All @@ -27,7 +27,7 @@ private void OnRequestRules(RequestRulesMessage message, EntitySessionEventArgs
}
catch (Exception)
{
Log.Debug("info", "Could not read server rules file.");
Log.Debug("Could not read server rules file.");
}
var response = new RulesMessage(title, rules);
RaiseNetworkEvent(response, eventArgs.SenderSession.Channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private void FireEmitter(EntityUid uid, ParticleAcceleratorPowerState strength,
var xformQuery = GetEntityQuery<TransformComponent>();
if (!xformQuery.TryGetComponent(uid, out var xform))
{
Logger.Error("ParticleAccelerator attempted to emit a particle without (having) a transform from which to base its initial position and orientation.");
Log.Error("ParticleAccelerator attempted to emit a particle without (having) a transform from which to base its initial position and orientation.");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void Spawn(EntityUid uid, ConditionalSpawnerComponent component)

if (component.Prototypes.Count == 0)
{
Logger.Warning($"Prototype list in ConditionalSpawnComponent is empty! Entity: {ToPrettyString(uid)}");
Log.Warning($"Prototype list in ConditionalSpawnComponent is empty! Entity: {ToPrettyString(uid)}");
return;
}

Expand All @@ -94,7 +94,7 @@ private void Spawn(EntityUid uid, RandomSpawnerComponent component)

if (component.Prototypes.Count == 0)
{
Logger.Warning($"Prototype list in RandomSpawnerComponent is empty! Entity: {ToPrettyString(uid)}");
Log.Warning($"Prototype list in RandomSpawnerComponent is empty! Entity: {ToPrettyString(uid)}");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ public void CalcExtendedAccess(Dictionary<EntityUid, int> jobsCount)

jobs.ExtendedAccess = count <= thresh;

Logger.DebugS(
"station", "Station {Station} on extended access: {ExtendedAccess}",
Log.Debug("Station {Station} on extended access: {ExtendedAccess}",
Name(station), jobs.ExtendedAccess);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Station/Systems/StationSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public void DeleteStation(EntityUid station, StationDataComponent? stationData =

if (xform.GridUid == EntityUid.Invalid)
{
Log.Debug("A");
Log.Debug("Unable to get owning station - GridUid invalid.");
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Store/Systems/StoreSystem.Listings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool TryAddListing(StoreComponent component, string listingId)
{
if (!_proto.TryIndex<ListingPrototype>(listingId, out var proto))
{
Logger.Error("Attempted to add invalid listing.");
Log.Error("Attempted to add invalid listing.");
return false;
}
return TryAddListing(component, proto);
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Strip/StrippableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ bool Check()

if (!_inventorySystem.TryGetSlot(target, slot, out var slotDef))
{
Logger.Error($"{ToPrettyString(user)} attempted to place an item in a non-existent inventory slot ({slot}) on {ToPrettyString(target)}");
Log.Error($"{ToPrettyString(user)} attempted to place an item in a non-existent inventory slot ({slot}) on {ToPrettyString(target)}");
return;
}

Expand Down Expand Up @@ -347,7 +347,7 @@ bool Check()

if (!_inventorySystem.TryGetSlot(target, slot, out var slotDef))
{
Logger.Error($"{ToPrettyString(user)} attempted to take an item from a non-existent inventory slot ({slot}) on {ToPrettyString(target)}");
Log.Error($"{ToPrettyString(user)} attempted to take an item from a non-existent inventory slot ({slot}) on {ToPrettyString(target)}");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Traits/TraitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent args)
{
if (!_prototypeManager.TryIndex<TraitPrototype>(traitId, out var traitPrototype))
{
Logger.Warning($"No trait found with ID {traitId}!");
Log.Warning($"No trait found with ID {traitId}!");
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using Content.Server.Worldgen.Components;
using Content.Server.Worldgen.Prototypes;
using Robust.Shared.Prototypes;
Expand Down Expand Up @@ -35,7 +35,7 @@ private void OnWorldChunkAdded(EntityUid uid, BiomeSelectionComponent component,
return;
}

Logger.Error($"Biome selection ran out of biomes to select? See biomes list: {component.Biomes}");
Log.Error($"Biome selection ran out of biomes to select? See biomes list: {component.Biomes}");
}

private void OnBiomeSelectionStartup(EntityUid uid, BiomeSelectionComponent component, ComponentStartup args)
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Worldgen/Systems/WorldgenConfigSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Server.Administration;
using Content.Server.Administration;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Events;
using Content.Server.Worldgen.Components;
Expand Down Expand Up @@ -74,7 +74,7 @@ private void OnLoadingMaps(RoundStartingEvent ev)
return;

var target = _map.GetMapEntityId(_gameTicker.DefaultMap);
Logger.Debug($"Trying to configure {_gameTicker.DefaultMap}, aka {ToPrettyString(target)} aka {target}");
Log.Debug($"Trying to configure {_gameTicker.DefaultMap}, aka {ToPrettyString(target)} aka {target}");
var cfg = _proto.Index<WorldgenConfigPrototype>(_worldgenConfig);

cfg.Apply(target, _ser, EntityManager); // Apply the config to the map.
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/DoAfter/SharedDoAfterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public async Task<DoAfterStatus> WaitDoAfter(DoAfterArgs doAfter, DoAfterCompone

if (doAfter.Delay <= TimeSpan.Zero)
{
Logger.Warning("Awaited instant DoAfters are not supported fully supported");
Log.Warning("Awaited instant DoAfters are not supported fully supported");
return DoAfterStatus.Finished;
}

Expand Down
23 changes: 10 additions & 13 deletions Content.Shared/Interaction/SharedInteractionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private bool HandleTryPullObject(ICommonSession? session, EntityCoordinates coor
{
if (!ValidateClientInput(session, coords, uid, out var userEntity))
{
Logger.InfoS("system.interaction", $"TryPullObject input validation failed");
Log.Info($"TryPullObject input validation failed");
return true;
}

Expand Down Expand Up @@ -203,7 +203,7 @@ private void HandleInteractInventorySlotEvent(InteractInventorySlotEvent msg, En
// client sanitization
if (!TryComp(item, out TransformComponent? itemXform) || !ValidateClientInput(args.SenderSession, itemXform.Coordinates, item, out var user))
{
Logger.InfoS("system.interaction", $"Inventory interaction validation failed. Session={args.SenderSession}");
Log.Info($"Inventory interaction validation failed. Session={args.SenderSession}");
return;
}

Expand All @@ -225,7 +225,7 @@ public bool HandleAltUseInteraction(ICommonSession? session, EntityCoordinates c
// client sanitization
if (!ValidateClientInput(session, coords, uid, out var user))
{
Logger.InfoS("system.interaction", $"Alt-use input validation failed");
Log.Info($"Alt-use input validation failed");
return true;
}

Expand All @@ -239,7 +239,7 @@ public bool HandleUseInteraction(ICommonSession? session, EntityCoordinates coor
// client sanitization
if (!ValidateClientInput(session, coords, uid, out var userEntity))
{
Logger.InfoS("system.interaction", $"Use input validation failed");
Log.Info($"Use input validation failed");
return true;
}

Expand Down Expand Up @@ -547,7 +547,7 @@ public bool InRangeUnobstructed(

if (length > MaxRaycastRange)
{
Logger.Warning("InRangeUnobstructed check performed over extreme range. Limiting CollisionRay size.");
Log.Warning("InRangeUnobstructed check performed over extreme range. Limiting CollisionRay size.");
length = MaxRaycastRange;
}

Expand Down Expand Up @@ -921,7 +921,7 @@ private bool HandleActivateItemInWorld(ICommonSession? session, EntityCoordinate
{
if (!ValidateClientInput(session, coords, uid, out var user))
{
Logger.InfoS("system.interaction", $"ActivateItemInWorld input validation failed");
Log.Info($"ActivateItemInWorld input validation failed");
return false;
}

Expand Down Expand Up @@ -1100,30 +1100,27 @@ protected bool ValidateClientInput(ICommonSession? session, EntityCoordinates co

if (!coords.IsValid(EntityManager))
{
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
Log.Info($"Invalid Coordinates: client={session}, coords={coords}");
return false;
}

if (IsClientSide(uid))
{
Logger.WarningS("system.interaction",
$"Client sent interaction with client-side entity. Session={session}, Uid={uid}");
Log.Warning($"Client sent interaction with client-side entity. Session={session}, Uid={uid}");
return false;
}

userEntity = session?.AttachedEntity;

if (userEntity == null || !userEntity.Value.Valid)
{
Logger.WarningS("system.interaction",
$"Client sent interaction with no attached entity. Session={session}");
Log.Warning($"Client sent interaction with no attached entity. Session={session}");
return false;
}

if (!Exists(userEntity))
{
Logger.WarningS("system.interaction",
$"Client attempted interaction with a non-existent attached entity. Session={session}, entity={userEntity}");
Log.Warning($"Client attempted interaction with a non-existent attached entity. Session={session}, entity={userEntity}");
return false;
}

Expand Down

0 comments on commit b1e3b79

Please sign in to comment.