2024-04-28 13:55:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.debug;
|
|
|
|
|
|
2024-05-08 10:22:04 +00:00
|
|
|
|
public static class LogCat
|
2024-04-28 13:55:19 +00:00
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
private static readonly StringBuilder StringBuilder = new StringBuilder();
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static StringBuilder HandleMessage(string message)
|
|
|
|
|
{
|
2024-05-08 10:22:04 +00:00
|
|
|
|
StringBuilder.Clear();
|
|
|
|
|
StringBuilder.Append(DateTime.Now.ToString("yyyy-M-d HH:mm:ss |"));
|
|
|
|
|
StringBuilder.Append(TranslationServer.Translate(message));
|
|
|
|
|
return StringBuilder;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Print log</para>
|
|
|
|
|
/// <para>打印日志</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">
|
|
|
|
|
///<para>message</para>
|
|
|
|
|
///<para>消息</para>
|
|
|
|
|
/// <para>This message supports localized output, assuming there is already a translation key, Hello = 你好, passing hello will output 你好.</para>
|
|
|
|
|
/// <para>这个消息支持本地化输出,假设已存在翻译key,Hello = 你好,传入Hello则会输出你好。</para>
|
|
|
|
|
/// </param>
|
|
|
|
|
public static void Log(string message)
|
|
|
|
|
{
|
|
|
|
|
GD.Print(HandleMessage(message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Print error log</para>
|
|
|
|
|
/// <para>打印错误日志</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">
|
|
|
|
|
///<para>message</para>
|
|
|
|
|
///<para>消息</para>
|
|
|
|
|
/// <para>This message supports localized output, assuming there is already a translation key, Hello = 你好, passing hello will output 你好.</para>
|
|
|
|
|
/// <para>这个消息支持本地化输出,假设已存在翻译key,Hello = 你好,传入Hello则会输出你好。</para>
|
|
|
|
|
/// </param>
|
|
|
|
|
public static void LogError(string message)
|
|
|
|
|
{
|
|
|
|
|
GD.PrintErr(HandleMessage(message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LogErrorWithFormat(string message, params object?[] args)
|
|
|
|
|
{
|
|
|
|
|
GD.PrintErr(string.Format(HandleMessage(message).ToString(), args));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void LogWithFormat(string message, params object?[] args)
|
|
|
|
|
{
|
|
|
|
|
GD.Print(string.Format(HandleMessage(message).ToString(), args));
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 14:56:27 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>This method is called when an exception is caught</para>
|
|
|
|
|
/// <para>当捕获异常后调用此方法</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
public static void WhenCaughtException(Exception e)
|
2024-04-28 13:55:19 +00:00
|
|
|
|
{
|
2024-05-10 14:56:27 +00:00
|
|
|
|
//Log an exception here or send it to the server.
|
|
|
|
|
//请在这里记录异常或将异常发送至服务器。
|
2024-04-28 13:55:19 +00:00
|
|
|
|
GD.PrintErr(HandleMessage(e.Message).Append('\n').Append(e.StackTrace));
|
|
|
|
|
}
|
|
|
|
|
}
|