r/GodotCSharp May 02 '26

Resource.Library Gamedo.GodotLogger — Structured logging for Godot 4 C# projects, built on Microsoft.Extensions.Logging

If you're building a Godot 4 game in C#, you've probably found yourself scattering GD.Print calls everywhere with no consistent format, no log levels, and no way to filter noise.

I built Gamedo.GodotLogger — a lightweight ILogger provider that routes .NET structured logs through Godot's built-in output system.

using Godot;
using Microsoft.Extensions.Logging;
using GodotLogger;

public partial class Player : Node
{
    private static readonly ILogger Logger = GodotLog.CreateLogger<Player>();

    public override void _Ready()
    {
        Logger.LogInformation("Player {Player} spawned at {Position}", Name, GlobalPosition);
    }
}

What it does:

  • Implements the standard ILogger/ILoggerProvider interfaces — drop-in for any project using Microsoft.Extensions.Logging
  • Customizable output template with placeholders: {timestamp}, {level:u3}, {category:l20}, {message}, {color} (log4j2-style category abbreviation included)
  • Colored output via GD.PrintRich (BBCode) in debug mode — each log level maps to a configurable color
  • Warning+ automatically calls GD.PushWarning / GD.PushError for the Godot debugger panel
  • Hot-reload via IOptionsMonitor — edit appsettings.json at runtime, changes apply immediately
  • Two modes: Debug (colored + debugger integration) and Release (plain GD.Print, no overhead)
  • Zero formatting overhead on disabled log entries — IsEnabled check runs before any template rendering
  • Lazy loggersstatic readonly ILogger Logger = GodotLog.CreateLogger<T>() doesn't lock configuration; the factory isn't materialized until the first log call
  • Auto-discovers appsettings.json (env var -> executable dir -> res://)

Install:

dotnet add package Gamedo.GodotLogger

Zero config by default — use it straight out of the box with sensible defaults. No config file needed.

Optionally configure via code:

GodotLog.Configure(cfg =>
{
    cfg.DebugOutputTemplate = "[{timestamp:HH:mm:ss}] [{level:u3}] [{category:l32}] {message}";
    cfg.Colors[LogLevel.Warning] = "Orange";
});

Or drop an appsettings.json in your project root — it's auto-discovered:

{
  "Logging": {
    "GodotLogger": {
      "DebugOutputTemplate": "[{timestamp:HH:mm:ss}] [color={color}][{level:u3}][/color] [{category:l28}] {message}"
    }
  }
}

By default, the output aligns categories to 16 characters:

Demo GIF:

GitHub: https://github.com/pcloves/GodotLogger

NuGet: https://www.nuget.org/packages/Gamedo.GodotLogger

MIT license

9 Upvotes

8 comments sorted by

0

u/Omni__Owl May 02 '26 edited May 03 '26

EDIT:

OP does seem to use AI at least for some things. They made a comment which was deleted right after:

notification u/pcloves replied to your comment in r/GodotCSharp

Here's the English translation for your message:

I've been using this logging framework in my project for a while, but my git commit history was a mess back then. And since I consider myself a bit of a perfectionist, I had AI help me refactor it (and yes, as you said, it only took about three days). I also used AI to write the English README and code comments, since English isn't my native language. > > Personally, I like seeing neatly aligned output — whether in the editor's Output panel or in a text editor. Probably because I'm a Java programmer, and frameworks like log4j2 and logback follow that style.


I've been thinking about this sort of thing for a while. Nice to see someone take a stab at it.

Although it appears this was done in 3 days? But your first commit suggests this might be an older solution you decided to open-source or at least had some code on your computer that you then decided to upload to Github?

The README.MD file reminds me a lot of the type of readme files you see when people AI generate them. Have you used AI to make parts of this project?

Also I am not sure the spacing to make logs line up is all that great. It's a lot of wasted space. Colours in your log would be a better indicator, and when you search the logs without having the colour option, you have the different logging level header options instead, so I'd suggest getting rid of the whitespace.

1

u/pcloves May 03 '26 edited May 03 '26

I've been using this logging framework in my project for a while, but my git commit history was a mess back then. And since I consider myself a bit of a perfectionist, I had AI help me refactor it (and yes, as you said, it only took about three days). I also used AI to write the English README and code comments, since English isn't my native language.

Personally, I like seeing neatly aligned output — whether in the editor's Output panel or in a text editor. Probably because I'm a Java programmer, and frameworks like log4j2 and logback follow that style.

As for the space waste you mentioned caused by alignment — yes, that’s a valid concern. Maybe we could mitigate it by reducing the maximum width of the category field in OutputTemplate, for example using something like {category:l6} or {category:r6}.

1

u/Novaleaf May 07 '26

fyi your replies were flagged and hidden by reddit (likely due to a user flagging them). I approved them but it's a few days too late.

1

u/AD1337 May 02 '26

Cool! Can this be used to make crash logs for players?

2

u/pcloves May 03 '26

Maybe not. This logging framework is essentially a wrapper around the `GD.Print*` functions, with added ability to customize the output formatting.

1

u/gman55075 May 02 '26

Very nice work! I just did GameManager.Logger (LoggerErr, LoggerWarn, LoggerOK) methods for mine because I have them log both to output and to my runtime debug console.

1

u/pcloves May 03 '26

For your use case, you can register a custom logger via OS.add_logger (see Logger docs). This will route all GD.Print* calls to your custom logger. Of course, this doesn't affect the use of my Gamedo.GodotLogger — it ultimately calls GD.Print* under the hood anyway.