https://github.com/mysteriousmilk/godotlogging
A logging library for Godot 4 (C#).
https://github.com/mysteriousmilk/godotlogging
csharp dotnet gamedev godot godot-engine
Last synced: 9 months ago
JSON representation
A logging library for Godot 4 (C#).
- Host: GitHub
- URL: https://github.com/mysteriousmilk/godotlogging
- Owner: MysteriousMilk
- License: mit
- Created: 2022-07-24T02:38:44.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T04:56:21.000Z (almost 2 years ago)
- Last Synced: 2025-08-30T08:24:18.097Z (10 months ago)
- Topics: csharp, dotnet, gamedev, godot, godot-engine
- Language: C#
- Homepage:
- Size: 32.2 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Godot Logging Library
[](https://www.nuget.org/packages/Godot.Logging/1.2/)\
[](https://www.nuget.org/packages/Godot.Logging/1.1.4/)
A C# logging library for the Godot game engine. The library provides several Log Targets needed to log messages in a variety of formats. This is intended to work with the .NET version of Godot (C#). The latest NuGet packages provide targets for .NET 6, .NET 7, and .NET 8.
## Version Compatibility
Different versions of Godot.Logging may support different version of the Godot SDK. See below.
**Godot.Logging v1.2.\*** -> Godot SDK 4.2.2 or greater\
**Godot.Logging v1.1.\*** -> Godot SDK 4.0.2 or greater
## Usage
#### Overview
Logging can be configured for use in just a few lines of code.
```C#
// Create a configuration for the logger
LogConfiguration config = new LogConfiguration();
config.RegisterTarget(new GDPrintTarget("GodotConsole"));
// Set the configuration
GodotLogger.SetConfiguration(config);
// Start logging messages!
GodotLogger.LogInfo("Hello Godot!");
```
#### Logging Exceptions
Exceptions may be logged as well.
```C#
try
{
throw new Exception(exMsg);
}
catch (Exception ex)
{
GodotLogger.LogException(ex, "An exception occurred.");
}
```
When logging excpetions, if preferred, the whole stack trace can be outputted in the log with the following setting.
```C#
GodotLogger.Instance.Configuration.IncludeExceptionCallStack = true;
```
#### Format Rules
Formatting rules (output format in the log) may be specified. In the LogConfiguration, you may specify 1 format rule per log level.
```C#
FormatRule infoRule = new FormatRule()
{
FormatText = "[${level}][${classname}.${methodname}] ${message}",
FormatLogLevel = LogLevel.Info
};
GodotLogger.Instance.Configuration.ApplyFormattingRule(infoRule);
```
As seen above, format rules may include macros to indicate parts of the format to be replace with log entry specific information. Here are the current macros that are supported.
**\${level}** - Log level associated with the log entry.\
**\${classname}** - Class or type name of the object from where the log entry was invoked.\
**\${methodname}** - Name of the method within the object from where the log entry was invoked.\
**\${message}** - The actual message recorded for the log entry / event.