Initial Checkin of Code
This commit is contained in:
parent
19b557ee9b
commit
0bee2ee47b
44 changed files with 7965 additions and 0 deletions
35
Library/Support/Logger.cs
Normal file
35
Library/Support/Logger.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PokemonLike.Library.Support;
|
||||
|
||||
public static class Logger
|
||||
{
|
||||
public static string ColorTable(LogLevel level) => level switch
|
||||
{
|
||||
LogLevel.None => "white",
|
||||
LogLevel.Error => "firebrick",
|
||||
LogLevel.Info => "white",
|
||||
LogLevel.Warn => "gold",
|
||||
LogLevel.Debug => "green",
|
||||
};
|
||||
|
||||
public static LogLevel LogLevel { get; set; } = LogLevel.Debug;
|
||||
|
||||
public static void Log(LogLevel level, params object[] message)
|
||||
{
|
||||
if (level > LogLevel) return;
|
||||
var timeStamp = $"[lb]{DateTime.Now:yyyy-MM-dd HH:mm:ss}[rb]";
|
||||
var callingMethod = new StackTrace().GetFrame(2)?.GetMethod();
|
||||
var lvl = $"{level}".ToUpper();
|
||||
var clsName = callingMethod?.DeclaringType?.Name == null ? "UnknownClass" : callingMethod!.DeclaringType!.Name;
|
||||
var mthdName = callingMethod?.Name == null ? "UnknownMethod" : callingMethod!.Name;
|
||||
var msg = $"{timeStamp} [lb][color={ColorTable(level)}]{lvl}[/color][rb] [color=cyan][lb]{clsName}->{mthdName}[rb][/color] ";
|
||||
Godot.GD.PrintRich([msg, ..message]);
|
||||
}
|
||||
|
||||
public static void Info(params object[] message) => Log(LogLevel.Info, message);
|
||||
public static void Warn(params object[] message) => Log(LogLevel.Warn, message);
|
||||
public static void Debug(params object[] message) => Log(LogLevel.Debug, message);
|
||||
public static void Error(params object[] message) => Log(LogLevel.Error, message);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue