mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
- 新增 GodotLog、DeferredLogger 和配置自动发现、热重载接线。 - 修复已缓存 logger 的级别判定与输出路径,使动态配置生效。 - 更新文档与追踪记录,明确当前收敛边界和恢复点。
133 lines
3.9 KiB
C#
133 lines
3.9 KiB
C#
using System;
|
|
using GFramework.Core.Abstractions.Logging;
|
|
using GFramework.Godot.Logging;
|
|
|
|
namespace GFramework.Godot.Tests.Logging;
|
|
|
|
[TestFixture]
|
|
public sealed class GodotLogTemplateTests
|
|
{
|
|
[Test]
|
|
public void Render_Should_Format_Timestamp_Level_Color_Category_And_Message()
|
|
{
|
|
var template = GodotLogTemplate.Parse("[{timestamp:yyyyMMdd}] [color={color}]{level:u3}[/color] [{category:l16}] {message}");
|
|
var context = new GodotLogRenderContext(
|
|
new DateTime(2026, 5, 2, 1, 2, 3, DateTimeKind.Utc),
|
|
LogLevel.Warning,
|
|
"Game.Services.Inventory",
|
|
"Loaded",
|
|
"orange",
|
|
string.Empty);
|
|
|
|
var result = template.Render(context);
|
|
|
|
Assert.That(result, Is.EqualTo("[20260502] [color=orange]WRN[/color] [G.S.Inventory ] Loaded"));
|
|
}
|
|
|
|
[Test]
|
|
public void Render_Should_Support_Lowercase_Level_Format()
|
|
{
|
|
var template = GodotLogTemplate.Parse("{level:l3}:{message}");
|
|
var context = new GodotLogRenderContext(
|
|
new DateTime(2026, 5, 2, 1, 2, 3, DateTimeKind.Utc),
|
|
LogLevel.Debug,
|
|
"Game",
|
|
"Ready",
|
|
"cyan",
|
|
string.Empty);
|
|
|
|
var result = template.Render(context);
|
|
|
|
Assert.That(result, Is.EqualTo("dbg:Ready"));
|
|
}
|
|
|
|
[Test]
|
|
public void Render_Should_Right_Align_Category()
|
|
{
|
|
var template = GodotLogTemplate.Parse("[{category:r10}]");
|
|
var context = new GodotLogRenderContext(
|
|
new DateTime(2026, 5, 2, 1, 2, 3, DateTimeKind.Utc),
|
|
LogLevel.Info,
|
|
"UI",
|
|
"Ready",
|
|
"white",
|
|
string.Empty);
|
|
|
|
var result = template.Render(context);
|
|
|
|
Assert.That(result, Is.EqualTo("[ UI]"));
|
|
}
|
|
|
|
[Test]
|
|
public void Render_Should_Preserve_Unknown_Placeholders()
|
|
{
|
|
var template = GodotLogTemplate.Parse("{message} {unknown}");
|
|
var context = new GodotLogRenderContext(
|
|
new DateTime(2026, 5, 2, 1, 2, 3, DateTimeKind.Utc),
|
|
LogLevel.Info,
|
|
"Game",
|
|
"Ready",
|
|
"white",
|
|
string.Empty);
|
|
|
|
var result = template.Render(context);
|
|
|
|
Assert.That(result, Is.EqualTo("Ready {unknown}"));
|
|
}
|
|
|
|
[Test]
|
|
public void Render_Should_Format_Padded_Level()
|
|
{
|
|
var template = GodotLogTemplate.Parse("{level:padded}");
|
|
var context = new GodotLogRenderContext(
|
|
new DateTime(2026, 5, 2, 1, 2, 3, DateTimeKind.Utc),
|
|
LogLevel.Info,
|
|
"Game",
|
|
"Ready",
|
|
"white",
|
|
string.Empty);
|
|
|
|
var result = template.Render(context);
|
|
|
|
Assert.That(result, Is.EqualTo("INFO "));
|
|
}
|
|
|
|
[Test]
|
|
public void Render_Should_Append_Properties_Placeholder()
|
|
{
|
|
var template = GodotLogTemplate.Parse("{message}{properties}");
|
|
var context = new GodotLogRenderContext(
|
|
new DateTime(2026, 5, 2, 1, 2, 3, DateTimeKind.Utc),
|
|
LogLevel.Info,
|
|
"Game",
|
|
"Ready",
|
|
"white",
|
|
" | Scene=Boot");
|
|
|
|
var result = template.Render(context);
|
|
|
|
Assert.That(result, Is.EqualTo("Ready | Scene=Boot"));
|
|
}
|
|
|
|
[Test]
|
|
public void Options_ForMinimumLevel_Should_Preserve_Fixed_Minimum_Level()
|
|
{
|
|
var options = GodotLoggerOptions.ForMinimumLevel(LogLevel.Warning);
|
|
|
|
Assert.That(options.Mode, Is.EqualTo(GodotLoggerMode.Debug));
|
|
Assert.That(options.DebugMinLevel, Is.EqualTo(LogLevel.Warning));
|
|
Assert.That(options.ReleaseMinLevel, Is.EqualTo(LogLevel.Warning));
|
|
}
|
|
|
|
[Test]
|
|
public void Options_Should_Use_Default_Color_When_Configured_Color_Is_Missing()
|
|
{
|
|
var options = new GodotLoggerOptions();
|
|
options.Colors.Remove(LogLevel.Error);
|
|
|
|
var result = options.GetColor(LogLevel.Error);
|
|
|
|
Assert.That(result, Is.EqualTo("red"));
|
|
}
|
|
}
|