-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathNetworkLog.cs
More file actions
97 lines (87 loc) · 3.75 KB
/
NetworkLog.cs
File metadata and controls
97 lines (87 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using MLAPI.Configuration;
using MLAPI.Messaging;
using MLAPI.Security;
using MLAPI.Serialization.Pooled;
using MLAPI.Transports;
using UnityEngine;
namespace MLAPI.Logging
{
/// <summary>
/// Helper class for logging
/// </summary>
public static class NetworkLog
{
/// <summary>
/// Gets the current log level.
/// </summary>
/// <value>The current log level.</value>
internal static LogLevel CurrentLogLevel
{
get
{
if (NetworkingManager.Singleton == null)
return LogLevel.Normal;
else
return NetworkingManager.Singleton.LogLevel;
}
}
// MLAPI internal logging
internal static void LogInfo(string message) => Debug.Log("[MLAPI] " + message);
internal static void LogWarning(string message) => Debug.LogWarning("[MLAPI] " + message);
internal static void LogError(string message) => Debug.LogError("[MLAPI] " + message);
/// <summary>
/// Logs an info log locally and on the server if possible.
/// </summary>
/// <param name="message">The message to log</param>
public static void LogInfoServer(string message) => LogServer(message, LogType.Info);
/// <summary>
/// Logs a warning log locally and on the server if possible.
/// </summary>
/// <param name="message">The message to log</param>
public static void LogWarningServer(string message) => LogServer(message, LogType.Warning);
/// <summary>
/// Logs an error log locally and on the server if possible.
/// </summary>
/// <param name="message">The message to log</param>
public static void LogErrorServer(string message) => LogServer(message, LogType.Error);
private static void LogServer(string message, LogType logType)
{
// Get the sender of the local log
ulong localId = NetworkingManager.Singleton != null ? NetworkingManager.Singleton.LocalClientId : 0;
switch (logType)
{
case LogType.Info:
LogInfoServerLocal(message, localId);
break;
case LogType.Warning:
LogWarningServerLocal(message, localId);
break;
case LogType.Error:
LogErrorServerLocal(message, localId);
break;
}
if (NetworkingManager.Singleton != null && !NetworkingManager.Singleton.IsServer && NetworkingManager.Singleton.NetworkConfig.EnableNetworkLogs)
{
using (PooledBitStream stream = PooledBitStream.Get())
{
using (PooledBitWriter writer = PooledBitWriter.Get(stream))
{
writer.WriteByte((byte)logType);
writer.WriteStringPacked(message);
InternalMessageSender.Send(NetworkingManager.Singleton.ServerClientId, MLAPIConstants.MLAPI_SERVER_LOG, Transport.MLAPI_INTERNAL_CHANNEL, stream, SecuritySendFlags.None);
}
}
}
}
internal static void LogInfoServerLocal(string message, ulong sender) => Debug.Log("[MLAPI_SERVER Sender=" + sender + "] " + message);
internal static void LogWarningServerLocal(string message, ulong sender) => Debug.LogWarning("[MLAPI_SERVER Sender=" + sender + "] " + message);
internal static void LogErrorServerLocal(string message, ulong sender) => Debug.LogError("[MLAPI_SERVER Sender=" + sender + "] " + message);
internal enum LogType
{
Info,
Warning,
Error,
None
}
}
}