From 6b8a8660ef8f759944c62d293740bce39b35cc69 Mon Sep 17 00:00:00 2001 From: GwWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Fri, 2 Jan 2026 12:52:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(logging):=20=E6=9B=B4=E6=96=B0=20Godot=20?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E5=99=A8=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加时间戳格式化到日志前缀中 - 为日志级别字符串添加右对齐格式 - 将异常信息直接追加到日志消息中 - 更新致命错误、错误、警告和普通日志的输出方法 - 添加了更详细的日志格式包括时间戳、级别和名称 --- GFramework.Godot/logging/GodotLogger.cs | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/GFramework.Godot/logging/GodotLogger.cs b/GFramework.Godot/logging/GodotLogger.cs index 3669844..a7defe4 100644 --- a/GFramework.Godot/logging/GodotLogger.cs +++ b/GFramework.Godot/logging/GodotLogger.cs @@ -13,26 +13,32 @@ public sealed class GodotLogger( { protected override void Write(LogLevel level, string message, Exception? exception) { - var prefix = $"[{level.ToString().ToUpper()}][{Name()}]"; + var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); + var levelStr = level.ToString().ToUpper().PadRight(7); + var logPrefix = $"[{timestamp}] {levelStr} [{Name()}]"; - // 将异常信息追加到日志消息中 - if (exception != null) message += "\n" + exception; + // 添加异常信息 + if (exception != null) + { + message += "\n" + exception; + } - // 根据日志级别选择不同的输出方法 + var logMessage = $"{logPrefix} {message}"; + + // 根据日志级别选择 Godot 输出方法 switch (level) { case LogLevel.Fatal: - GD.PushError($"{prefix} {message}"); + GD.PushError(logMessage); break; - case LogLevel.Error: - GD.PrintErr($"{prefix} {message}"); + GD.PrintErr(logMessage); break; case LogLevel.Warning: - GD.PushWarning($"{prefix} {message}"); + GD.PushWarning(logMessage); break; - default: - GD.Print($"{prefix} {message}"); + default: // Trace / Debug / Info + GD.Print(logMessage); break; } }