66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BITKit
|
|
{
|
|
public static class BIT4Log
|
|
{
|
|
const string _debugLevel = "DebugLevel";
|
|
public static event Action<string> OnLog;
|
|
public static event Action<Exception> OnException;
|
|
public static event Action<string> OnWarning;
|
|
public static event Action<ConsoleColor> OnSetConsoleColor;
|
|
public static event Action OnNextLine;
|
|
static Type currentType;
|
|
[ExcuteOnAwake]
|
|
public static void Start()
|
|
{
|
|
}
|
|
[ExcuteOnStop]
|
|
public static void Stop()
|
|
{
|
|
OnLog = null;
|
|
OnException = null;
|
|
OnWarning = null;
|
|
OnNextLine = null;
|
|
}
|
|
public static void Log(object x, int debugLevel = 0, ConsoleColor color = ConsoleColor.White)
|
|
{
|
|
if (x is not null)
|
|
{
|
|
OnSetConsoleColor?.Invoke(color);
|
|
OnLog?.Invoke(x.ToString());
|
|
}
|
|
}
|
|
public static void Log<T>(object x, int debugLevel = 0, ConsoleColor color = ConsoleColor.White)
|
|
{
|
|
if (currentType == typeof(T))
|
|
{
|
|
Log(x, debugLevel);
|
|
}
|
|
else
|
|
{
|
|
OnNextLine?.Invoke();
|
|
Log($"{typeof(T).Name}:{x}", debugLevel);
|
|
}
|
|
currentType = typeof(T);
|
|
}
|
|
public static void LogException(Exception e)
|
|
{
|
|
OnException?.Invoke(e);
|
|
}
|
|
public static void Warnning(object x, int debugLevel = 0)
|
|
{
|
|
OnWarning?.Invoke(x.ToString());
|
|
}
|
|
public static void Warnning<T>(object x, int debugLevel = 0)
|
|
{
|
|
Warnning($"{typeof(T).Name}:{x}", debugLevel);
|
|
}
|
|
}
|
|
}
|