API Log - shmellyorc/Box GitHub Wiki
Log
Namespace: Box.Systems
Provides file-based logging of messages, objects, and assertions. Logs are automatically flushed on exit and unhandled exceptions are captured.
Constructors
internal Log()
Initializes the singleton Instance
, sets up the log file in the application data folder (named by date), registers for unhandled exceptions and engine exit, and writes a startup message.
Properties
Name | Type | Description |
---|---|---|
static Log Instance |
Log |
Global logging instance, created on first construction. |
Methods
Signature | Description |
---|---|
void Print(string value) |
Write a string message to the log. |
void Print(object value) |
Write an object’s ToString() output to the log. |
void PrintObjcet(object title, string text) |
Write a titled message: "[TypeName]: text" . |
void PrintTabbed(params object[] values) |
Write multiple values separated by tabs. |
void PrintMany(params object[] values) |
Write multiple values separated by spaces. |
void Assert(bool condition, string message = "") |
If condition is true, throw an Exception with the optional message; otherwise do nothing. |
Usage Example
// Ensure the log is initialized (usually done internally):
var log = new Log(); // sets Log.Instance
// Write messages
log.Print("Game started");
log.Print(playerScore);
// Titled print
log.PrintObjcet(playerEntity, "entered the zone");
// Tabbed output
timerMgr.Add("spawn", 3f, false, () => log.PrintTabbed("spawn", enemyId, enemyPosition));
// Assertion (will throw if condition true)
log.Assert(playerHealth <= 0, "Player health dropped to zero");