Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

Latest commit

 

History

History
70 lines (53 loc) · 2.53 KB

README.md

File metadata and controls

70 lines (53 loc) · 2.53 KB

Chickensoft.GoDotLog

Chickensoft Badge Discord Read the docs line coverage branch coverage

Warning

Chickensoft.GoDotLog has been deprecated and replaced with Chickensoft.Log and Chickensoft.Log.Godot.

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());

Install

dotnet add package Chickensoft.GoDotLog