-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLogger.cs
More file actions
80 lines (63 loc) · 2.96 KB
/
Logger.cs
File metadata and controls
80 lines (63 loc) · 2.96 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
namespace ScriptedEvents.API.Features
{
using CommandSystem;
using Exiled.API.Features;
using ScriptedEvents.API.Enums;
using LogInternal = Exiled.API.Features.Log;
public static class Logger
{
public static void Log(string message, LogType logType, Script script = null, int? printableLine = null)
{
if (MainPlugin.Configs.DisableAllLogs)
return;
if (script is not null)
message = $"[Script: {script.Name}] [L: {(printableLine == null ? script.CurrentLine + 1 : printableLine)}] {message}";
switch (logType)
{
case LogType.Error:
LogInternal.Error(message);
break;
case LogType.Warning:
LogInternal.Warn(message);
break;
case LogType.Info:
LogInternal.Info(message);
break;
case LogType.Debug:
if (script is not null && script.Debug)
script.DebugLog(message);
else
LogInternal.Debug(message);
break;
}
}
public static void Info(string message, Script source = null) => Log(message, LogType.Info, source);
public static void Warn(string message, Script source = null) => Log(message, LogType.Warning, source);
public static void Error(string message, Script source = null) => Log(message, LogType.Error, source);
public static void Debug(string message, Script source = null) => Log(message, LogType.Debug, source);
public static void ScriptError(string message, Script source, bool fatal = false, int? printableLine = null)
{
string formattedMessage = $"[Script: {source.Name}] [Line: {printableLine ?? source.CurrentLine + 1}] " + message;
string broadcastMessage = $"<b><size=40>{(fatal ? "Fatal e" : "E")}rror when running the '{source.Name}' script.\n<size=30>See the console for more details.";
ICommandSender sender = source.Sender;
switch (source.Context)
{
case ExecuteContext.RemoteAdmin:
Player ply = Player.Get(sender);
ply?.RemoteAdminMessage(formattedMessage, false, MainPlugin.Singleton.Name);
if (MainPlugin.Configs.BroadcastIssues)
ply?.Broadcast(5, broadcastMessage);
break;
case ExecuteContext.PlayerConsole:
Player ply2 = Player.Get(sender);
ply2?.SendConsoleMessage(formattedMessage, "red");
if (MainPlugin.Configs.BroadcastIssues)
ply2?.Broadcast(5, broadcastMessage);
break;
default:
Warn(formattedMessage);
break;
}
}
}
}