Skip to content

Commit

Permalink
New logging system, deleted the 'L' class.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWillett committed Oct 6, 2024
1 parent e883341 commit 46c7bec
Show file tree
Hide file tree
Showing 101 changed files with 3,644 additions and 2,358 deletions.
17 changes: 17 additions & 0 deletions UncreatedWarfare.Tests/LoggingFormattingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Uncreated.Warfare.Players.Management;
using Uncreated.Warfare.Translations;
using Uncreated.Warfare.Translations.Languages;
using Uncreated.Warfare.Util;

namespace Uncreated.Warfare.Tests;
public class LoggingFormattingTests
Expand Down Expand Up @@ -65,6 +66,22 @@ public void Setup()
_formatter = _container.Resolve<ITranslationValueFormatter>();
}

[Test]
public void TempTextConverter()
{
Console.WriteLine(TerminalColorHelper.WrapMessageWithColor(ConsoleColor.Red, "CRT", true));
Console.WriteLine(TerminalColorHelper.WrapMessageWithColor(ConsoleColor.DarkRed, "ERR", true));
Console.WriteLine(TerminalColorHelper.WrapMessageWithColor(ConsoleColor.DarkYellow, "WRN", true));
Console.WriteLine(TerminalColorHelper.WrapMessageWithColor(ConsoleColor.DarkCyan, "INF", true));
Console.WriteLine(TerminalColorHelper.WrapMessageWithColor(ConsoleColor.Gray, "DBG", true));
Console.WriteLine(TerminalColorHelper.WrapMessageWithColor(ConsoleColor.Gray, "TRC", true));

Console.WriteLine(TerminalColorHelper.WrapMessageWithColor(ConsoleColor.Yellow, "TRC", false));
Console.WriteLine(TerminalColorHelper.WrapMessageWithColor(ConsoleColor.Red, "TRC", false));

Console.WriteLine(TerminalColorHelper.GetTerminalColorSequenceString(-2712187, false));
}

[Test]
public void TestEmptyFormat()
{
Expand Down
10 changes: 6 additions & 4 deletions UncreatedWarfare/Commands/DutyCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Uncreated.Warfare.Interaction;
using Uncreated.Warfare.Interaction.Commands;
Expand All @@ -23,6 +22,7 @@ public class DutyCommand : IExecutableCommand
private readonly DutyCommandTranslations _translations;
private readonly ITranslationService _translationService;
private readonly ChatService _chatService;
private readonly ILogger<DutyCommand> _logger;

private const string Help = "Swap your duty status between on and off. For admins and trial admins.";

Expand All @@ -35,14 +35,16 @@ public DutyCommand(
SignInstancer signs,
TranslationInjection<DutyCommandTranslations> translations,
ITranslationService translationService,
ChatService chatService)
ChatService chatService,
ILogger<DutyCommand> logger)
{
_translations = translations.Value;
_permissions = permissions;
_warfare = warfare;
_signs = signs;
_translationService = translationService;
_chatService = chatService;
_logger = logger;
}

/// <summary>
Expand Down Expand Up @@ -164,7 +166,7 @@ public async UniTask ExecuteAsync(CancellationToken token)
Context.Reply(_translations.DutyOffFeedback);
_chatService.Broadcast(_translationService.SetOf.AllPlayersExcept(Context.CallerId.m_SteamID), _translations.DutyOffBroadcast, Context.Player);

L.Log($"{Context.Player.Names.PlayerName} ({Context.CallerId.m_SteamID.ToString(CultureInfo.InvariantCulture)}) went off duty (owner: {isOwner}, admin: {isAdmin}, trial admin: {isTrial}, staff: {isStaff}).", ConsoleColor.Cyan);
_logger.LogInformation("{0} ({1}) went off duty (owner: {2}, admin: {3}, trial admin: {4}, staff: {5}).", Context.Player.Names.PlayerName, Context.CallerId, isOwner, isAdmin, isTrial, isStaff);
ActionLog.Add(ActionLogType.DutyChanged, "OFF DUTY", Context.CallerId.m_SteamID);

// PlayerManager.NetCalls.SendDutyChanged.NetInvoke(Context.CallerId.m_SteamID, false);
Expand All @@ -174,7 +176,7 @@ public async UniTask ExecuteAsync(CancellationToken token)
Context.Reply(_translations.DutyOnFeedback);
_chatService.Broadcast(_translationService.SetOf.AllPlayersExcept(Context.CallerId.m_SteamID), _translations.DutyOnBroadcast, Context.Player);

L.Log($"{Context.Player.Names.PlayerName} ({Context.CallerId.m_SteamID.ToString(CultureInfo.InvariantCulture)}) went on duty (owner: {isOwner}, admin: {isAdmin}, trial admin: {isTrial}, staff: {isStaff}).", ConsoleColor.Cyan);
_logger.LogInformation("{0} ({1}) went on duty (owner: {2}, admin: {3}, trial admin: {4}, staff: {5}).", Context.Player.Names.PlayerName, Context.CallerId, isOwner, isAdmin, isTrial, isStaff);
ActionLog.Add(ActionLogType.DutyChanged, "ON DUTY", Context.CallerId.m_SteamID);

// PlayerManager.NetCalls.SendDutyChanged.NetInvoke(Context.CallerId.m_SteamID, true);
Expand Down
11 changes: 5 additions & 6 deletions UncreatedWarfare/Commands/GroupCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Layouts.Teams;
using Uncreated.Warfare.Lobby;
Expand All @@ -19,18 +18,18 @@ public class GroupCommand : IExecutableCommand
private readonly GroupCommandTranslations _translations;
private readonly ITeamManager<Team> _teamManager;
private readonly IFactionDataStore _factionDataStore;
private readonly LobbyZoneManager _lobbyManager;
private readonly ILogger<GroupCommand> _logger;

private static readonly PermissionLeaf PermissionJoin = new PermissionLeaf("commands.group.join", unturned: false, warfare: true);

/// <inheritdoc />
public CommandContext Context { get; set; }

public GroupCommand(TranslationInjection<GroupCommandTranslations> translations, ITeamManager<Team> teamManager, IFactionDataStore factionDataStore, LobbyZoneManager lobbyManager)
public GroupCommand(TranslationInjection<GroupCommandTranslations> translations, ITeamManager<Team> teamManager, IFactionDataStore factionDataStore, ILogger<GroupCommand> logger)
{
_teamManager = teamManager;
_factionDataStore = factionDataStore;
_lobbyManager = lobbyManager;
_logger = logger;
_translations = translations.Value;
}

Expand Down Expand Up @@ -107,7 +106,7 @@ public async UniTask ExecuteAsync(CancellationToken token)
if (newTeam != null && newTeam.IsValid)
{
Context.Reply(_translations.JoinedGroup, newTeam.GroupId.m_SteamID, newTeam.Faction.Name, newTeam.Faction.Color);
L.Log($"{Context.Player.Names.PlayerName} ({Context.CallerId.m_SteamID}) joined group \"{newTeam.Faction.Name}\": {newTeam} (ID {groupInfo.groupID}).", ConsoleColor.Cyan);
_logger.LogInformation("{0} ({1}) joined group \"{2}\": {3} (ID {4}).", Context.Player.Names.PlayerName, Context.CallerId, newTeam.Faction, newTeam, groupInfo.groupID);
Context.LogAction(ActionLogType.ChangeGroupWithCommand, "GROUP: " + newTeam.Faction.Name.ToUpper());
}
else
Expand Down
6 changes: 4 additions & 2 deletions UncreatedWarfare/Commands/Kit/KitGiveLoadoutCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ namespace Uncreated.Warfare.Commands;
[Command("loadout", "l"), SubCommandOf(typeof(KitGiveCommand))]
internal class KitGiveLoadoutCommand : IExecutableCommand
{
private readonly ILogger<KitGiveLoadoutCommand> _logger;
private readonly KitCommandTranslations _translations;
public CommandContext Context { get; set; }

public KitGiveLoadoutCommand(TranslationInjection<KitCommandTranslations> translations)
public KitGiveLoadoutCommand(TranslationInjection<KitCommandTranslations> translations, ILogger<KitGiveLoadoutCommand> logger)
{
_logger = logger;
_translations = translations.Value;
}

Expand All @@ -37,7 +39,7 @@ public UniTask ExecuteAsync(CancellationToken token)

Context.Player.Component<KitPlayerComponent>().UpdateKit(null);

ItemUtility.GiveItems(player, items, true);
ItemUtility.GiveItems(player, items, _logger, true);

Context.Reply(_translations.RequestDefaultLoadoutGiven, @class);
return UniTask.CompletedTask;
Expand Down
27 changes: 14 additions & 13 deletions UncreatedWarfare/Commands/_DebugCommands.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using DanielWillett.ReflectionTools;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.ExceptionServices;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Locations;
using Uncreated.Warfare.Logging;
using Uncreated.Warfare.Players.Permissions;
using Uncreated.Warfare.Util;

Expand Down Expand Up @@ -127,7 +126,7 @@ public async UniTask ExecuteAsync(CancellationToken token)
}
catch (Exception ex)
{
L.LogError(ex.InnerException ?? ex);
_serviceProvider.GetRequiredService<ILogger<DebugCommand>>().LogError(ex.InnerException ?? ex, "Error executing test command.");
throw Context.ReplyString($"Ran into an error while executing: <#ff758f>{testFunction.Name}</color> - <#ff758f>{Accessor.Formatter.Format((ex.InnerException ?? ex).GetType())}</color>.", "ff8c69");
}
}
Expand Down Expand Up @@ -214,16 +213,18 @@ private void carto()

Context.ReplyString($"Converted back: {CartographyUtility.MapToWorld.MultiplyPoint3x4(worldToMap)}.");

L.Log("m2w: " + Environment.NewLine + CartographyUtility.WorldToMap.ToString("F3"));
L.Log("m2wt: " + CartographyUtility.WorldToMap.GetPosition().ToString("F3"));
L.Log("m2wr: " + CartographyUtility.WorldToMap.GetRotation().eulerAngles.ToString("F3"));
L.Log("m2ws: " + CartographyUtility.WorldToMap.lossyScale.ToString("F3"));
L.Log("w2m: " + Environment.NewLine + CartographyUtility.MapToWorld.ToString("F3"));
L.Log("w2mt: " + CartographyUtility.MapToWorld.GetPosition().ToString("F3"));
L.Log("w2mr: " + CartographyUtility.MapToWorld.GetRotation().eulerAngles.ToString("F3"));
L.Log("w2ms: " + CartographyUtility.MapToWorld.lossyScale.ToString("F3"));
L.Log("Img size: " + CartographyUtility.MapImageSize);
L.Log("Cpt size: " + CartographyUtility.CaptureAreaSize.ToString("F3"));
ILogger<DebugCommand> logger = _serviceProvider.GetRequiredService<ILogger<DebugCommand>>();

logger.LogInformation("m2w: " + Environment.NewLine + CartographyUtility.WorldToMap.ToString("F3"));
logger.LogInformation("m2wt: " + CartographyUtility.WorldToMap.GetPosition().ToString("F3"));
logger.LogInformation("m2wr: " + CartographyUtility.WorldToMap.GetRotation().eulerAngles.ToString("F3"));
logger.LogInformation("m2ws: " + CartographyUtility.WorldToMap.lossyScale.ToString("F3"));
logger.LogInformation("w2m: " + Environment.NewLine + CartographyUtility.MapToWorld.ToString("F3"));
logger.LogInformation("w2mt: " + CartographyUtility.MapToWorld.GetPosition().ToString("F3"));
logger.LogInformation("w2mr: " + CartographyUtility.MapToWorld.GetRotation().eulerAngles.ToString("F3"));
logger.LogInformation("w2ms: " + CartographyUtility.MapToWorld.lossyScale.ToString("F3"));
logger.LogInformation("Img size: " + CartographyUtility.MapImageSize);
logger.LogInformation("Cpt size: " + CartographyUtility.CaptureAreaSize.ToString("F3"));
}
#if false
private const string UsageGiveXp = "/test givexp <player> <amount> [team - required if offline]";
Expand Down
11 changes: 5 additions & 6 deletions UncreatedWarfare/Components/GuidedMissileComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using Uncreated.Warfare.Configuration;
using Uncreated.Warfare.Logging;

namespace Uncreated.Warfare.Components;

Expand Down Expand Up @@ -64,13 +63,13 @@ public void Initialize(GameObject projectile, Player firer, IServiceProvider ser
return;
}
}
L.LogDebug("GUIDED MISSILE ERROR: player firing not found");
//L.LogDebug("GUIDED MISSILE ERROR: player firing not found");
}
else
L.LogDebug("GUIDED MISSILE ERROR: player was not in a vehicle");
//else
//L.LogDebug("GUIDED MISSILE ERROR: player was not in a vehicle");
}
else
L.LogDebug("GUIDED MISSILE ERROR: could not find rigidbody");
//else
//L.LogDebug("GUIDED MISSILE ERROR: could not find rigidbody");
}
[UsedImplicitly]
private void FixedUpdate()
Expand Down
17 changes: 4 additions & 13 deletions UncreatedWarfare/Components/HeatSeekingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using Uncreated.Framework.UI;
using Uncreated.Warfare.Configuration;
using Uncreated.Warfare.Logging;

namespace Uncreated.Warfare.Components;
internal class HeatSeekingController : MonoBehaviour // attach to a turrent's 'Aim' gameobject to allow it to control projectiles
Expand Down Expand Up @@ -51,7 +50,7 @@ private void FixedUpdate()
}
}

public void Initialize(float horizontalRange, float verticalRange, IAssetLink<EffectAsset>? lockOnEffect, float aquisitionTime, float timeOutTime)
public void Initialize(float horizontalRange, float verticalRange, IAssetLink<EffectAsset>? lockOnEffect, float aquisitionTime, float timeOutTime, ILogger logger)
{
_vehicle = GetComponentInParent<InteractableVehicle>();
_horizontalRange = horizontalRange;
Expand All @@ -71,10 +70,10 @@ public void Initialize(float horizontalRange, float verticalRange, IAssetLink<Ef

if (!lockOnEffect.TryGetAsset(out _effect))
{
L.LogWarning($"HEATSEAKER ERROR: Lock on sound effect not found: {lockOnEffect?.Guid.ToString() ?? "unknown"}.");
logger.LogWarning("HEATSEAKER ERROR: Lock on sound effect not found: {0}.", lockOnEffect?.Guid ?? Guid.Empty);
}
}
public void Initialize(float range, IAssetLink<EffectAsset> lockOnEffect, float aquisitionTime, float timeOutTime)
public void Initialize(float range, IAssetLink<EffectAsset> lockOnEffect, float aquisitionTime, float timeOutTime, ILogger logger)
{
_vehicle = GetComponentInParent<InteractableVehicle>();
_horizontalRange = range;
Expand Down Expand Up @@ -102,7 +101,7 @@ public void Initialize(float range, IAssetLink<EffectAsset> lockOnEffect, float

if (!lockOnEffect.TryGetAsset(out _effect))
{
L.LogWarning($"HEATSEAKER ERROR: Lock on sound effect not found: {lockOnEffect?.Guid.ToString() ?? "unknown"}.");
logger.LogWarning("HEATSEAKER ERROR: Lock on sound effect not found: {0}.", lockOnEffect?.Guid ?? Guid.Empty);
}
}

Expand Down Expand Up @@ -226,8 +225,6 @@ private void LockOn(Transform? newTarget, Player? gunner)
_timeOfAquisition = Time.time;
Status = ELockOnMode.ACQUIRING;

L.LogDebug($" AA: acquriing...");

if (gunner != null)
PlayLockOnSound(gunner);
}
Expand All @@ -237,9 +234,6 @@ private void LockOn(Transform? newTarget, Player? gunner)

if (timeSinceAquisition >= _aquisitionTime)
{
if (Status != ELockOnMode.LOCKED_ON)
L.LogDebug($" AA: LOCKED");

Status = ELockOnMode.LOCKED_ON;

if (LockOnTarget.TryGetComponent(out VehicleComponent v) && gunner != null)
Expand All @@ -259,8 +253,6 @@ private void PlayLockOnSound(Player gunner)
if (_effect == null || gunner == null)
return;

L.LogDebug($" tone: playing...");

EffectManager.sendUIEffect(_effect.id, LockOnEffectKey, gunner.channel.owner.transportConnection, true);
}
private void CancelLockOnSound(Player gunner)
Expand All @@ -269,7 +261,6 @@ private void CancelLockOnSound(Player gunner)
return;

EffectManager.ClearEffectByGuid(_effect.GUID, gunner.channel.owner.transportConnection);
L.LogDebug($" tone: cancelled");
}

public bool IsInRange(Vector3 target)
Expand Down
25 changes: 12 additions & 13 deletions UncreatedWarfare/Components/HeatSeekingMissileComponent.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#if DEBUG
#endif
using System;
using Microsoft.Extensions.DependencyInjection;
using System;
using Uncreated.Warfare.Configuration;
using Uncreated.Warfare.Logging;
using Random = UnityEngine.Random;

namespace Uncreated.Warfare.Components;
Expand Down Expand Up @@ -72,12 +71,12 @@ public void Initialize(GameObject projectile, Player firer, IServiceProvider ser

_controller.MissilesInFlight.Add(this);

L.LogDebug($" AA: Missile launched - {_controller.Status}");
//L.LogDebug($" AA: Missile launched - {_controller.Status}");
}

private void OnDestroy()
{
L.LogDebug("Missile destroyed. In flight: " + _controller.MissilesInFlight.Count);
//L.LogDebug("Missile destroyed. In flight: " + _controller.MissilesInFlight.Count);
_controller.MissilesInFlight.Remove(this);
}

Expand All @@ -94,20 +93,20 @@ private void FixedUpdate()
{
if (_previousTarget == null)
{
L.LogDebug($"Missile {gameObject.GetInstanceID()} initial target set");
//L.LogDebug($"Missile {gameObject.GetInstanceID()} initial target set");
_previousTarget = _controller.LockOnTarget;
}

if (_lastKnownTarget != null && _lastKnownTarget != _previousTarget)
{
_allowedPathAlterations--;
_previousTarget = _lastKnownTarget;
L.LogDebug($"Missile {gameObject.GetInstanceID()} detected path change. Alterations left: " + _allowedPathAlterations);
//L.LogDebug($"Missile {gameObject.GetInstanceID()} detected path change. Alterations left: " + _allowedPathAlterations);
}

if (_allowedPathAlterations > 0)
{
L.LogDebug($"Missile {gameObject.GetInstanceID()} successfully tracking target");
//L.LogDebug($"Missile {gameObject.GetInstanceID()} successfully tracking target");
_lastKnownTarget = _controller.LockOnTarget;
}
}
Expand All @@ -118,10 +117,10 @@ private void FixedUpdate()

if (_lastKnownTarget != null && Vector3.Angle(_projectile.transform.forward, _lastKnownTarget.position - _projectile.transform.position) > 40)
{
L.LogDebug("In flight: " + _controller.MissilesInFlight.Count);
//L.LogDebug("In flight: " + _controller.MissilesInFlight.Count);
_lost = true;
L.LogDebug($"Missile {gameObject.GetInstanceID()} lost its target");
L.LogDebug("In flight: " + _controller.MissilesInFlight.Count);
//L.LogDebug($"Missile {gameObject.GetInstanceID()} lost its target");
//L.LogDebug("In flight: " + _controller.MissilesInFlight.Count);
}

Vector3 idealDirection;
Expand All @@ -143,10 +142,10 @@ private void FixedUpdate()
if (!_rigidbody.useGravity)
{
_rigidbody.useGravity = true;
L.LogDebug($"Missile {gameObject.GetInstanceID()} timed out");
L.LogDebug("In flight: " + _controller.MissilesInFlight.Count);
//L.LogDebug($"Missile {gameObject.GetInstanceID()} timed out");
//L.LogDebug("In flight: " + _controller.MissilesInFlight.Count);
_controller.MissilesInFlight.Remove(this);
L.LogDebug("In flight: " + _controller.MissilesInFlight.Count);
//L.LogDebug("In flight: " + _controller.MissilesInFlight.Count);

}
}
Expand Down
Loading

0 comments on commit 46c7bec

Please sign in to comment.