Traveller/scripts/debug/LogCat.cs
2024-04-28 21:55:19 +08:00

65 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Text;
using Godot;
namespace ColdMint.scripts.debug;
public class LogCat
{
private static readonly StringBuilder _stringBuilder = new StringBuilder();
private static StringBuilder HandleMessage(string message)
{
_stringBuilder.Clear();
_stringBuilder.Append(DateTime.Now.ToString("yyyy-M-d HH:mm:ss |"));
_stringBuilder.Append(TranslationServer.Translate(message));
return _stringBuilder;
}
/// <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>这个消息支持本地化输出假设已存在翻译keyHello = 你好传入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>这个消息支持本地化输出假设已存在翻译keyHello = 你好传入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));
}
public static void LogError(Exception e)
{
GD.PrintErr(HandleMessage(e.Message).Append('\n').Append(e.StackTrace));
}
}