Made the logging colors smarter.
This commit is contained in:
parent
bb02fa6e90
commit
3a34ec2045
|
@ -63,7 +63,34 @@ public class DiscordBot
|
|||
LogLevel = LogSeverity.Warning
|
||||
});
|
||||
|
||||
client.Log += async (a) => await Task.Run(() => LogToDiscordLogChannel($"Discord: {a.Source}", a.Severity.ToString(), a.Exception?.ToString() ?? "null", (int)a.Severity <= 2 ? ConsoleColor.Yellow : ConsoleColor.Black));
|
||||
client.Log += async (a) => await Task.Run(() =>
|
||||
{
|
||||
//as time goes on, we may encounter logged info that we literally don't care about. Fill out an if statement to properly
|
||||
//filter it out to avoid logging it to discord.
|
||||
//if (a.Message.StartsWith(""))
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
string message = a.Message + (a.Exception != null ? "Exception: " + a.Exception.ToString() : "");
|
||||
ConsoleColor col;
|
||||
switch (a.Severity)
|
||||
{
|
||||
default:
|
||||
case LogSeverity.Info:
|
||||
case LogSeverity.Debug:
|
||||
col = ConsoleColor.White;
|
||||
break;
|
||||
case LogSeverity.Critical:
|
||||
case LogSeverity.Error:
|
||||
col = ConsoleColor.Red;
|
||||
break;
|
||||
case LogSeverity.Warning:
|
||||
col = ConsoleColor.Yellow;
|
||||
break;
|
||||
}
|
||||
|
||||
LogToDiscordLogChannel($"Discord: {a.Source}", a.Severity.ToString(), message, col);
|
||||
});
|
||||
try
|
||||
{
|
||||
await client.LoginAsync(Discord.TokenType.Bot, localSettings.Token);
|
||||
|
|
|
@ -29,7 +29,7 @@ public class Server {
|
|||
Socket socket = token.HasValue ? await serverSocket.AcceptAsync(token.Value) : await serverSocket.AcceptAsync();
|
||||
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
|
||||
|
||||
Logger.Warn($"Accepted connection for client {socket.RemoteEndPoint}");
|
||||
Logger.Notify($"Accepted connection for client {socket.RemoteEndPoint}");
|
||||
|
||||
try {
|
||||
#pragma warning disable CS4014
|
||||
|
|
|
@ -9,6 +9,8 @@ public class Logger {
|
|||
|
||||
public string Name { get; set; }
|
||||
|
||||
public void Notify(string text) => Handler?.Invoke(Name, "Info", text, ConsoleColor.Green);
|
||||
|
||||
public void Info(string text) => Handler?.Invoke(Name, "Info", text, ConsoleColor.White);
|
||||
|
||||
public void Warn(string text) => Handler?.Invoke(Name, "Warn", text, ConsoleColor.Yellow);
|
||||
|
|
Loading…
Reference in New Issue