Skip to content

Commit

Permalink
feat: Use logger framework for NetworkClient (#1685)
Browse files Browse the repository at this point in the history
* Use logger framework for NetworkClient

* Update Assets/Mirror/Runtime/NetworkClient.cs

Co-authored-by: vis2k <info@noobtuts.com>
  • Loading branch information
paulpach and miwarnec committed Apr 11, 2020
1 parent 54a3650 commit 6e92bf5
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Assets/Mirror/Runtime/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public enum ConnectState
/// </summary>
public static class NetworkClient
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(NetworkClient));

/// <summary>
/// The registered network message handlers.
/// </summary>
Expand Down Expand Up @@ -60,7 +62,7 @@ public static class NetworkClient
/// <param name="address"></param>
public static void Connect(string address)
{
if (LogFilter.Debug) Debug.Log("Client Connect: " + address);
if (logger.LogEnabled()) logger.Log("Client Connect: " + address);

RegisterSystemHandlers(false);
Transport.activeTransport.enabled = true;
Expand All @@ -80,7 +82,7 @@ public static void Connect(string address)
/// <param name="uri">Address of the server to connect to</param>
public static void Connect(Uri uri)
{
if (LogFilter.Debug) Debug.Log("Client Connect: " + uri);
if (logger.LogEnabled()) logger.Log("Client Connect: " + uri);

RegisterSystemHandlers(false);
Transport.activeTransport.enabled = true;
Expand All @@ -96,7 +98,7 @@ public static void Connect(Uri uri)

internal static void ConnectHost()
{
if (LogFilter.Debug) Debug.Log("Client Connect Host to Server");
logger.Log("Client Connect Host to Server");

RegisterSystemHandlers(true);

Expand Down Expand Up @@ -151,7 +153,7 @@ static void InitializeTransportHandlers()

static void OnError(Exception exception)
{
Debug.LogException(exception);
logger.LogException(exception);
}

static void OnDisconnected()
Expand All @@ -169,7 +171,7 @@ internal static void OnDataReceived(ArraySegment<byte> data, int channelId)
{
connection.TransportReceive(data, channelId);
}
else Debug.LogError("Skipped Data message handling because connection is null.");
else logger.LogError("Skipped Data message handling because connection is null.");
}

static void OnConnected()
Expand All @@ -185,7 +187,7 @@ static void OnConnected()
NetworkTime.UpdateClient();
connection.InvokeHandler(new ConnectMessage(), -1);
}
else Debug.LogError("Skipped Connect message handling because connection is null.");
else logger.LogError("Skipped Connect message handling because connection is null.");
}

/// <summary>
Expand Down Expand Up @@ -242,12 +244,12 @@ static void RemoveTransportHandlers()
{
if (connectState != ConnectState.Connected)
{
Debug.LogError("NetworkClient Send when not connected to a server");
logger.LogError("NetworkClient Send when not connected to a server");
return false;
}
return connection.Send(message, channelId);
}
Debug.LogError("NetworkClient Send with no connection");
logger.LogError("NetworkClient Send with no connection");
return false;
}

Expand Down Expand Up @@ -312,7 +314,7 @@ public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool
int msgType = MessagePacker.GetId<T>();
if (handlers.ContainsKey(msgType))
{
if (LogFilter.Debug) Debug.Log("NetworkClient.RegisterHandler replacing " + handler + " - " + msgType);
if (logger.LogEnabled()) logger.Log("NetworkClient.RegisterHandler replacing " + handler + " - " + msgType);
}
handlers[msgType] = MessagePacker.MessageHandler(handler, requireAuthentication);
}
Expand Down Expand Up @@ -346,7 +348,7 @@ public static void RegisterHandler<T>(Action<T> handler, bool requireAuthenticat
/// </summary>
public static void Shutdown()
{
if (LogFilter.Debug) Debug.Log("Shutting down client.");
logger.Log("Shutting down client.");
ClientScene.Shutdown();
connectState = ConnectState.None;
handlers.Clear();
Expand Down

0 comments on commit 6e92bf5

Please sign in to comment.