Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit 9c382cc

Browse files
Remove all statics from Logger
1 parent ef95f0f commit 9c382cc

15 files changed

Lines changed: 39 additions & 37 deletions

File tree

Scripts/Msc/Commands/CommandDebug.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public override void Run(string[] args)
1818

1919
if (args[0] == "a")
2020
if (NetworkManager.IsServerRunning())
21-
Logger.LogDebug(NetworkManager.GameServer.Players.Print());
21+
GameManager.Logger.LogDebug(NetworkManager.GameServer.Players.Print());
2222
}
2323
}
2424
}

Scripts/Msc/Commands/CommandHelp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public class CommandHelp : Command
1212
.Select(Activator.CreateInstance).Cast<Command>()
1313
.Select(x => x.GetType().Name.Replace("Command", "").ToLower()).ToList();
1414

15-
public override void Run(string[] args) => Logger.Log($"Commands:\n{CommandNames.Print()}");
15+
public override void Run(string[] args) => GameManager.Logger.Log($"Commands:\n{CommandNames.Print()}");
1616
}
1717
}

Scripts/Msc/UIGameConsole.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void _on_Console_text_entered(string text)
4949
if (command != null)
5050
command.Run(inputArr.Skip(1).ToArray());
5151
else
52-
Logger.Log($"The command '{cmd}' does not exist");
52+
GameManager.Logger.Log($"The command '{cmd}' does not exist");
5353

5454
Console.Clear();
5555
}

Scripts/Netcode/Client/ENetClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async void Start(string ip, ushort port)
6161
}
6262
catch (Exception e)
6363
{
64-
Logger.LogErr(e, "Client");
64+
GameManager.Logger.LogErr(e, "Client");
6565
}
6666
}
6767

@@ -70,7 +70,7 @@ public async void Start(string ip, ushort port)
7070
/// </summary>
7171
public void Stop() => ENetCmds.Enqueue(new ThreadCmd<ENetOpcode>(ENetOpcode.ClientWantsToDisconnect));
7272

73-
public void Log(object obj) => Logger.Log($"[Client]: {obj}", ConsoleColor.Yellow);
73+
public void Log(object obj) => GameManager.Logger.Log($"[Client]: {obj}", ConsoleColor.Yellow);
7474

7575
/// <summary>
7676
/// This is in the ENet thread, anything from the ENet thread can be used here

Scripts/Netcode/Client/GodotCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task Dequeue()
2222

2323
if (!ENetClient.HandlePacket.ContainsKey(opcode))
2424
{
25-
Logger.LogWarning($"[Client]: Received malformed opcode: {opcode} (Ignoring)");
25+
GameManager.Logger.LogWarning($"[Client]: Received malformed opcode: {opcode} (Ignoring)");
2626
break;
2727
}
2828

@@ -33,7 +33,7 @@ public async Task Dequeue()
3333
}
3434
catch (System.IO.EndOfStreamException ex)
3535
{
36-
Logger.LogWarning($"[Client]: Received malformed opcode: {opcode} {ex.Message} (Ignoring)");
36+
GameManager.Logger.LogWarning($"[Client]: Received malformed opcode: {opcode} {ex.Message} (Ignoring)");
3737
break;
3838
}
3939
await handlePacket.Handle();

Scripts/Netcode/Common/Server/ENetServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task Start(ushort port, int maxClients)
4747
}
4848
catch (Exception e)
4949
{
50-
Logger.LogErr(e, "Server");
50+
GameManager.Logger.LogErr(e, "Server");
5151
}
5252
}
5353

@@ -75,7 +75,7 @@ public void Kick(uint id, DisconnectOpcode opcode)
7575

7676
public void Send(ServerPacketOpcode opcode, APacket data, PacketFlags flags = PacketFlags.Reliable, params Peer[] peers) => Outgoing.Enqueue(new ServerPacket((byte)opcode, flags, data, peers));
7777

78-
public void Log(object obj) => Logger.Log($"[Server]: {obj}", ConsoleColor.Cyan);
78+
public void Log(object obj) => GameManager.Logger.Log($"[Server]: {obj}", ConsoleColor.Cyan);
7979

8080
protected Peer[] GetOtherPeers(uint id)
8181
{
@@ -188,7 +188,7 @@ private Task ENetThreadWorker(ushort port, int maxClients)
188188

189189
if (!HandlePacket.ContainsKey(opcode))
190190
{
191-
Logger.LogWarning($"[Server]: Received malformed opcode: {opcode} (Ignoring)");
191+
GameManager.Logger.LogWarning($"[Server]: Received malformed opcode: {opcode} (Ignoring)");
192192
break;
193193
}
194194

@@ -199,7 +199,7 @@ private Task ENetThreadWorker(ushort port, int maxClients)
199199
}
200200
catch (System.IO.EndOfStreamException e)
201201
{
202-
Logger.LogWarning($"[Server]: Received malformed opcode: {opcode} {e.Message} (Ignoring)");
202+
GameManager.Logger.LogWarning($"[Server]: Received malformed opcode: {opcode} {e.Message} (Ignoring)");
203203
break;
204204
}
205205
handlePacket.Handle(netEvent.Peer);

Scripts/Netcode/Common/Utils/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static bool Duplicate<TKey, TValue>(this IDictionary<TKey, TValue> dict,
1414
{
1515
if (dict.ContainsKey(key))
1616
{
17-
Logger.LogWarning($"'{caller}' tried to add duplicate key '{key}' to dictionary\n" +
17+
GameManager.Logger.LogWarning($"'{caller}' tried to add duplicate key '{key}' to dictionary\n" +
1818
$" at {path} line:{lineNumber}");
1919
return true;
2020
}
@@ -29,7 +29,7 @@ public static bool DoesNotHave<TKey, TValue>(this IDictionary<TKey, TValue> dict
2929
{
3030
if (!dict.ContainsKey(key))
3131
{
32-
Logger.LogWarning($"'{caller}' tried to access non-existent key '{key}' from dictionary\n" +
32+
GameManager.Logger.LogWarning($"'{caller}' tried to access non-existent key '{key}' from dictionary\n" +
3333
$" at {path} line:{lineNumber}");
3434
return true;
3535
}

Scripts/Netcode/Common/Utils/GodotFileManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static bool LoadDir(string path, System.Action<Directory, string> action)
2424
var error = dir.Open($"res://{path}");
2525
if (error != Error.Ok)
2626
{
27-
Logger.LogWarning($"Failed to open {path}");
27+
GameManager.Logger.LogWarning($"Failed to open {path}");
2828
return false;
2929
}
3030

Scripts/Netcode/Common/Utils/Logger.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55

66
namespace GodotModules
77
{
8-
public static class Logger
8+
public class Logger
99
{
10-
private static ConcurrentQueue<ThreadCmd<LoggerOpcode>> Messages = new ConcurrentQueue<ThreadCmd<LoggerOpcode>>();
10+
private ConcurrentQueue<ThreadCmd<LoggerOpcode>> Messages = new ConcurrentQueue<ThreadCmd<LoggerOpcode>>();
1111

12-
public static void LogErr(Exception ex, string hint = "")
12+
public void LogErr(Exception ex, string hint = "")
1313
{
1414
Messages.Enqueue(new ThreadCmd<LoggerOpcode>(LoggerOpcode.LogError, new GodotError
1515
{
1616
Exception = ex,
1717
Hint = hint
1818
}));
1919
}
20-
public static void LogTODO(object v, ConsoleColor color = ConsoleColor.White) => Log($"[TODO]: {v}", color);
21-
public static void LogWarning(object v, ConsoleColor color = ConsoleColor.Yellow) => Log($"[Warning]: {v}", color);
22-
public static void LogDebug(object v, ConsoleColor color = ConsoleColor.Magenta, bool trace = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
20+
public void LogTODO(object v, ConsoleColor color = ConsoleColor.White) => Log($"[TODO]: {v}", color);
21+
public void LogWarning(object v, ConsoleColor color = ConsoleColor.Yellow) => Log($"[Warning]: {v}", color);
22+
public void LogDebug(object v, ConsoleColor color = ConsoleColor.Magenta, bool trace = true, [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
2323
{
2424
var path = "";
2525
if (trace)
@@ -32,7 +32,7 @@ public static void LogDebug(object v, ConsoleColor color = ConsoleColor.Magenta,
3232
Color = color
3333
}));
3434
}
35-
public static void Log(object v, ConsoleColor color = ConsoleColor.Gray)
35+
public void Log(object v, ConsoleColor color = ConsoleColor.Gray)
3636
{
3737
Messages.Enqueue(new ThreadCmd<LoggerOpcode>(LoggerOpcode.LogMessage, new GodotMessage
3838
{
@@ -41,7 +41,7 @@ public static void Log(object v, ConsoleColor color = ConsoleColor.Gray)
4141
}));
4242
}
4343

44-
public static void LogMs(Action code)
44+
public void LogMs(Action code)
4545
{
4646
var watch = new Stopwatch();
4747
watch.Start();
@@ -50,7 +50,7 @@ public static void LogMs(Action code)
5050
Log($"Took {watch.ElapsedMilliseconds} ms");
5151
}
5252

53-
public static void Dequeue()
53+
public void Dequeue()
5454
{
5555
if (Messages.TryDequeue(out ThreadCmd<LoggerOpcode> cmd))
5656
{

Scripts/Netcode/Common/Utils/NetworkManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override void _Ready()
2727
ENetInitialized = ENet.Library.Initialize();
2828
if (!ENetInitialized)
2929
{
30-
Logger.LogWarning("Failed to initialize ENet! Remember ENet-CSharp.dll AND enet.dll are required in order for ENet to run properly!");
30+
GameManager.Logger.LogWarning("Failed to initialize ENet! Remember ENet-CSharp.dll AND enet.dll are required in order for ENet to run properly!");
3131
}
3232
}
3333

@@ -80,7 +80,7 @@ private static async Task ExitCleanup()
8080
{
8181
GameServerStillRunning++;
8282
if (GameServerStillRunning > 4)
83-
Logger.LogDebug("Game server taking a long time to stop");
83+
GameManager.Logger.LogDebug("Game server taking a long time to stop");
8484
await Task.Delay(100);
8585
}
8686
}
@@ -94,7 +94,7 @@ private static async Task ExitCleanup()
9494
{
9595
GameClientStillRunning++;
9696
if (GameClientStillRunning > 4)
97-
Logger.LogDebug("Game client taking a long time to stop");
97+
GameManager.Logger.LogDebug("Game client taking a long time to stop");
9898
await Task.Delay(100);
9999
}
100100
}
@@ -106,7 +106,7 @@ private static async Task ExitCleanup()
106106
}
107107
catch (Exception e)
108108
{
109-
Logger.LogErr(e, "Game exit cleanup");
109+
GameManager.Logger.LogErr(e, "Game exit cleanup");
110110
await Task.Delay(3000);
111111
}
112112

0 commit comments

Comments
 (0)