Skip to content

Opinionated Godot logging interface and console implementation for C#

License

Notifications You must be signed in to change notification settings

chickensoft-games/GoDotLog

Repository files navigation

Chickensoft.GoDotLog

Chickensoft Badge Discord Read the docs line coverage branch coverage

Opinionated Godot logging interface and console implementation for C#.


Chickensoft.GoDotLog

public class MyEntity {
  // Create a log which outputs messages prefixed with the name of the class.
  private ILog _log = new GDLog(nameof(MyClass));
}

Logs can perform a variety of common actions (and output messages if they fail automatically):

_log.Print("My message");

_log.Warn("My message");

_log.Err("My message");

// Run a potentially unsafe action. Any errors thrown from the action will
// be output by the log. An optional error handler callback can be provided
// which will be invoked before the exception is re-thrown.
_log.Run(
  () => { _log.Print("Potentially unsafe action"); },
  (e) => {
    _log.Err("Better clean up after myself...whatever I did failed.");
  }
);

// Throw an assertion exception with the given message if the assertion fails.
_log.Assert(node.Name == "MyNode", "Must be valid node name.");

// Return the value of a function or a fallback value.
var result = _log.Always<T>(
  () => new Random().Next(0, 10) > 5 ? "valid value" : null,
  "fallback value"
);

// Print a decently formatted stack trace.
_log.Print(new StackTrace());

About

Opinionated Godot logging interface and console implementation for C#

Resources

License

Stars

Watchers

Forks

Packages

No packages published