Skip to content

Commit

Permalink
fix: check for log level for warnings (#445)
Browse files Browse the repository at this point in the history
* fix: check for log level for warnings

* remove unnecessary changes

* fix smell
  • Loading branch information
uweeby committed Nov 23, 2020
1 parent 3e8c9ea commit 90013ea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Assets/Mirror/Runtime/ClientObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ internal void OnUpdateVarsMessage(UpdateVarsMessage msg)
}
else
{
logger.LogWarning("Did not find target for sync message for " + msg.netId + " . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message.");
if (logger.WarnEnabled()) logger.LogWarning("Did not find target for sync message for " + msg.netId + " . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message.");
}
}

Expand Down
6 changes: 3 additions & 3 deletions Assets/Mirror/Runtime/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected internal void SendRpcInternal(Type invokeClass, string rpcName, Networ
// This cannot use Server.active, as that is not specific to this object.
if (!IsServer)
{
logger.LogWarning("ClientRpc " + rpcName + " called on un-spawned object: " + name);
if (logger.WarnEnabled()) logger.LogWarning("ClientRpc " + rpcName + " called on un-spawned object: " + name);
return;
}

Expand Down Expand Up @@ -326,7 +326,7 @@ protected internal void SendTargetRpcInternal(INetworkConnection conn, Type invo
// This cannot use Server.active, as that is not specific to this object.
if (!IsServer)
{
logger.LogWarning("ClientRpc " + rpcName + " called on un-spawned object: " + name);
if (logger.WarnEnabled()) logger.LogWarning("ClientRpc " + rpcName + " called on un-spawned object: " + name);
return;
}

Expand Down Expand Up @@ -380,7 +380,7 @@ internal protected void SetSyncVarNetworkIdentity(NetworkIdentity newIdentity, r
if (newIdentity != null)
{
newNetId = newIdentity.NetId;
if (newNetId == 0)
if (newNetId == 0 && logger.WarnEnabled())
{
logger.LogWarning("SetSyncVarNetworkIdentity NetworkIdentity " + newIdentity + " has a zero netId. Maybe it is not spawned yet?");
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Runtime/ServerObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void OnServerRpcMessage(INetworkConnection conn, ServerRpcMessage msg)
{
if (!server.Spawned.TryGetValue(msg.netId, out NetworkIdentity identity) || identity is null)
{
logger.LogWarning("Spawned object not found when handling ServerRpc message [netId=" + msg.netId + "]");
if (logger.WarnEnabled()) logger.LogWarning("Spawned object not found when handling ServerRpc message [netId=" + msg.netId + "]");
return;
}
Skeleton skeleton = RemoteCallHelper.GetSkeleton(msg.functionHash);
Expand All @@ -375,7 +375,7 @@ void OnServerRpcMessage(INetworkConnection conn, ServerRpcMessage msg)
// only allow the ServerRpc if clientAuthorityOwner
if (skeleton.cmdRequireAuthority && identity.ConnectionToClient != conn)
{
logger.LogWarning("ServerRpc for object without authority [netId=" + msg.netId + "]");
if (logger.WarnEnabled()) logger.LogWarning("ServerRpc for object without authority [netId=" + msg.netId + "]");
return;
}

Expand Down

0 comments on commit 90013ea

Please sign in to comment.