Kanda Foundation 0.8.0
Loading...
Searching...
No Matches
Logging

The Kanda SDK provides a custom logging implementation, KandaLog, which wraps the Unity Logging package. This custom logger includes standardized tags and additional contextual information, ensuring consistency across all logs generated by the Kanda SDK.

Introduction

KandaLog is designed to replace the typical UnityEngine.Debug.Log method. By using KandaLog, developers can produce logs that are easier to parse and understand, especially when debugging or reviewing logs from live applications.

Key Methods

Write

Logs a simple message with the default LogType.Log.

KandaLog.Write("Application started successfully.");

Write with Logging Severity

Logs a message with a specified logging severity (e.g., LogType.Warning, LogType.Error).

KandaLog.Write("A transition to session scene was requested, but this is already the active scene.", LogType.Warning);

Write with World Context

Logs a message with additional context about the ECS world.

KandaLog.Write("Loading initial game state.", world);

WriteManaged

KandaLog is burstable, meaning that it can be used in Burst-compiled code. However, it lengths of logs are restricted to a maximum of 512 bytes. If logs exceed this length, a truncation exception might will be thrown.

We provide KandaLog.WriteManaged which can be triggered from managed code and does not impose restrictions on the length of logs.

KandaLog.WriteManaged($"A long log with a stack trace: {ex.Message}.");

WriteSendRpc

Logs a message indicating that an RPC (Remote Procedure Call) is being sent.

KandaLog.WriteSendRpc("to request player data.", world);

WriteHandleRpc

Logs a message indicating that an RPC is being handled.

KandaLog.WriteHandleRpc("to update player status.", world);

Log Output Examples

Logs in the Unity Console will appear as follows:

Kanda SDK: Application started successfully.
Kanda SDK: A transition to session scene was requested, but this is already the active scene.
Kanda SDK: (Client World) Loading initial game state.
Kanda SDK: (Client World) Sending RPC to request player data.
Kanda SDK: (Server World) Handling RPC to update player status.

The added annotations makes it easier to observe app flows and discover relevant logs, for example when reviewing logs produced by dedicated servers.

Unity Console Tips

  • Strip logging callstack: Enable this to prevent the logger class from appearing at the top of all logs.
  • Log entry: Set to "1 line" for a more compact and easy-to-read log.
  • Show timestamp: Typically disable this for cleaner logs, but enable temporarily if timing information is relevant.
  • Use Monospace font: Enable for good looks...