This repository has been archived by the owner on Sep 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cs
55 lines (47 loc) · 2.03 KB
/
Logger.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
46
47
48
49
50
51
52
53
54
55
using System;
using System.Threading.Tasks;
using Discord;
using Tomat.Logging.Utilities;
namespace Tomat.Logging
{
public static class Logger
{
private static void PrivateLog(string message, LogLevel level, string source, bool removePadding = false)
{
Console.ForegroundColor = ConsoleUtils.ConvertToConsoleColor(level);
Console.WriteLine(
$"[{DateTime.UtcNow} (UTC)] [{ConsoleUtils.ConvertLogLevelToString(level)}] [{source}]{(removePadding ? "" : " ")}{message}");
}
/// <summary>
/// Logs a <see cref="LogLevel.Debug"/> message.
/// </summary>
public static void Debug(string message) => PrivateLog(message, LogLevel.Debug, " Self");
/// <summary>
/// Logs a <see cref="LogLevel.Info"/> message.
/// </summary>
public static void Info(string message) => PrivateLog(message, LogLevel.Info, " Self");
/// <summary>
/// Logs a <see cref="LogLevel.Warn"/> message.
/// </summary>
public static void Warn(string message) => PrivateLog(message, LogLevel.Warn, " Self");
/// <summary>
/// Logs a <see cref="LogLevel.Error"/> message.
/// </summary>
public static void Error(string message) => PrivateLog(message, LogLevel.Error, " Self");
/// <summary>
/// Logs a <see cref="LogLevel.Fatal"/> message.
/// </summary>
public static void Fatal(string message) => PrivateLog(message, LogLevel.Fatal, " Self");
/// <summary>
/// Method used for logging Discord.NET messages and awaitable messages.
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static Task TaskLog(LogMessage message)
{
PrivateLog(message.ToString(prependTimestamp: false, padSource: null),
LoggerUtils.ConvertToLogLevel(message.Severity), message.Source, true);
return Task.CompletedTask;
}
}
}