-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathDefaultUnityLogger.cs
45 lines (42 loc) · 1.54 KB
/
DefaultUnityLogger.cs
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
using System;
namespace WSNet2
{
/// <summary>
/// Unity環境でデフォルトで使用されるLogger
/// </summary>
public class DefaultUnityLogger : IWSNet2Logger<WSNet2LogPayload>
{
public WSNet2LogPayload Payload { get; } = new WSNet2LogPayload();
public void Log(WSNet2LogLevel logLevel, Exception exception, string format, params object[] args)
{
var msg = $"{string.Format(format, args)}\nPayload: User={Payload.UserId}, Room={Payload.RoomId}, RoomNum={Payload.RoomNum}";
switch (logLevel)
{
case WSNet2LogLevel.Critical:
case WSNet2LogLevel.Error:
UnityEngine.Debug.LogError(msg);
if (exception != null)
{
UnityEngine.Debug.LogException(exception);
}
break;
case WSNet2LogLevel.Warning:
if (exception != null)
{
msg = $"{msg}: {exception.Message}";
}
UnityEngine.Debug.LogWarning(msg);
break;
case WSNet2LogLevel.Information:
case WSNet2LogLevel.Debug:
case WSNet2LogLevel.Trace:
if (exception != null)
{
msg = $"{msg}: {exception.Message}";
}
UnityEngine.Debug.Log(msg);
break;
}
}
}
}