From fdd097b7789d3c0a465c4d4e29bbde128fd94195 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Fri, 20 Sep 2024 10:59:55 -0400 Subject: [PATCH] fix(SWT): Improved logging --- .../StandAlone/WebSocketClientStandAlone.cs | 2 +- .../SimpleWeb/SimpleWeb/Common/Log.cs | 16 ++++++++-------- .../SimpleWeb/SimpleWeb/Common/ReadHelper.cs | 4 ++-- .../SimpleWeb/SimpleWeb/Common/ReceiveLoop.cs | 7 ++----- .../SimpleWeb/SimpleWeb/Common/SendLoop.cs | 7 ++----- .../SimpleWeb/Server/WebSocketServer.cs | 17 ++++------------- 6 files changed, 19 insertions(+), 34 deletions(-) diff --git a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/StandAlone/WebSocketClientStandAlone.cs b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/StandAlone/WebSocketClientStandAlone.cs index 48dc37b35..2ca44be04 100644 --- a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/StandAlone/WebSocketClientStandAlone.cs +++ b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/StandAlone/WebSocketClientStandAlone.cs @@ -101,7 +101,7 @@ void ConnectAndReceiveLoop(Uri serverAddress) ReceiveLoop.Loop(config); } catch (ThreadInterruptedException e) { Log.InfoException(e); } - catch (ThreadAbortException e) { Log.InfoException(e); } + catch (ThreadAbortException e) { Log.Error("[SWT-WebSocketClientStandAlone]: Thread Abort Exception"); } catch (Exception e) { Log.Exception(e); } finally { diff --git a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/Log.cs b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/Log.cs index eb9e721f3..fe0c4ecdb 100644 --- a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/Log.cs +++ b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/Log.cs @@ -138,13 +138,13 @@ public static void Verbose(string msg) public static void Verbose(string msg, T arg1) { if (minLogLevel > Levels.Verbose) return; - Verbose($"{msg} {arg1}"); + Verbose(String.Format(msg, arg1)); } public static void Verbose(string msg, T1 arg1, T2 arg2) { if (minLogLevel > Levels.Verbose) return; - Verbose($"{msg} {arg1} {arg2}"); + Verbose(String.Format(msg, arg1, arg2)); } /// @@ -168,13 +168,13 @@ static void Info(string msg, ConsoleColor consoleColor = ConsoleColor.Cyan) public static void Info(string msg, T arg1, ConsoleColor consoleColor = ConsoleColor.Cyan) { if (minLogLevel > Levels.Info) return; - Info($"{msg} {arg1}", consoleColor); + Info(String.Format(msg, arg1), consoleColor); } public static void Info(string msg, T1 arg1, T2 arg2, ConsoleColor consoleColor = ConsoleColor.Cyan) { if (minLogLevel > Levels.Info) return; - Info($"{msg} {arg1} {arg2}", consoleColor); + Info(String.Format(msg, arg1, arg2), consoleColor); } /// @@ -218,7 +218,7 @@ public static void Warn(string msg) public static void Warn(string msg, T arg1) { if (minLogLevel > Levels.Warn) return; - Warn($"{msg} {arg1}"); + Warn(String.Format(msg, arg1)); } /// @@ -243,19 +243,19 @@ public static void Error(string msg) public static void Error(string msg, T arg1) { if (minLogLevel > Levels.Error) return; - Error($"{msg} {arg1}"); + Error(String.Format(msg, arg1)); } public static void Error(string msg, T1 arg1, T2 arg2) { if (minLogLevel > Levels.Error) return; - Error($"{msg} {arg1} {arg2}"); + Error(String.Format(msg, arg1, arg2)); } public static void Error(string msg, T1 arg1, T2 arg2, T3 arg3) { if (minLogLevel > Levels.Error) return; - Error($"{msg} {arg1} {arg2} {arg3}"); + Error(String.Format(msg, arg1, arg2, arg3)); } /// diff --git a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/ReadHelper.cs b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/ReadHelper.cs index 36bcb16f5..a56edfd86 100644 --- a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/ReadHelper.cs +++ b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/ReadHelper.cs @@ -20,7 +20,7 @@ public static int Read(Stream stream, byte[] outBuffer, int outOffset, int lengt { int read = stream.Read(outBuffer, outOffset + received, length - received); if (read == 0) - throw new ReadHelperException("returned 0"); + throw new ReadHelperException("[SWT-ReadHelper]: Read returned 0"); received += read; } @@ -35,7 +35,7 @@ public static int Read(Stream stream, byte[] outBuffer, int outOffset, int lengt } if (received != length) - throw new ReadHelperException("returned not equal to length"); + throw new ReadHelperException("[SWT-ReadHelper]: received not equal to length"); return outOffset + received; } diff --git a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/ReceiveLoop.cs b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/ReceiveLoop.cs index 724fbeda5..ff5b7108b 100644 --- a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/ReceiveLoop.cs +++ b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/ReceiveLoop.cs @@ -72,12 +72,9 @@ public static void Loop(Config config) } } catch (ThreadInterruptedException e) { Log.InfoException(e); } - catch (ThreadAbortException e) { Log.InfoException(e); } + catch (ThreadAbortException e) { Log.Error("[SWT-ReceiveLoop]: Thread Abort Exception"); } catch (ObjectDisposedException e) { Log.InfoException(e); } - catch (ReadHelperException e) - { - Log.InfoException(e); - } + catch (ReadHelperException e) { Log.InfoException(e); } catch (SocketException e) { // this could happen if wss client closes stream diff --git a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/SendLoop.cs b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/SendLoop.cs index 47fbd03dd..24c4ce07d 100644 --- a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/SendLoop.cs +++ b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Common/SendLoop.cs @@ -116,11 +116,8 @@ public static void Loop(Config config) Log.Verbose("[SWT-SendLoop]: {0} Not Connected", conn); } catch (ThreadInterruptedException e) { Log.InfoException(e); } - catch (ThreadAbortException e) { Log.InfoException(e); } - catch (Exception e) - { - Log.Exception(e); - } + catch (ThreadAbortException e) { Log.Error("[SWT-SendLoop]: Thread Abort Exception"); } + catch (Exception e) { Log.Exception(e); } finally { Profiler.EndThreadProfiling(); diff --git a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Server/WebSocketServer.cs b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Server/WebSocketServer.cs index 14a6a3222..3771f1e05 100644 --- a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Server/WebSocketServer.cs +++ b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Server/WebSocketServer.cs @@ -97,7 +97,7 @@ void acceptLoop() } } catch (ThreadInterruptedException e) { Log.InfoException(e); } - catch (ThreadAbortException e) { Log.InfoException(e); } + catch (ThreadAbortException e) { Log.Error("[SWT-WebSocketServer]: Thread Abort Exception"); } catch (Exception e) { Log.Exception(e); } } @@ -160,18 +160,9 @@ void HandshakeAndReceiveLoop(Connection conn) ReceiveLoop.Loop(receiveConfig); } - catch (ThreadInterruptedException e) - { - Log.Error("[SWT-WebSocketServer]: Handshake ThreadInterruptedException {0}", e.Message); - } - catch (ThreadAbortException e) - { - Log.Error("[SWT-WebSocketServer]: Handshake ThreadAbortException {0}", e.Message); - } - catch (Exception e) - { - Log.Error("[SWT-WebSocketServer]: Handshake Exception {0}", e.Message); - } + catch (ThreadInterruptedException e) { Log.InfoException(e); } + catch (ThreadAbortException e) { Log.Error("[SWT-WebSocketServer]: Thread Abort Exception"); } + catch (Exception e) { Log.Exception(e); } finally { // close here in case connect fails