Log Handler
On this page
Overview
The Prysm integration in Unity3D logs all internal SDK messages inside the built-in Unity3D editor console. This helps you understand what the state of the Prysm plugin is. You can see the detailed implementation in CohtmlPackage/Runtime/Detail/Logging/CohtmlLogHandler.cs
.
Generally, the CohtmlLogHandler
class catches the logs coming from the internal SDK and re-routes them to the LogWriter
class which outputs them to the Console
editor window of the Unity3D engine. The default implementation of the LogWriter
is located in CohtmlPackage/Runtime/Detail/Logging/LogWriter.cs
and it uses the following format:
[Cohtml] (Info) Message from Cohtml!
Debug
or Trace
.Implementing a custom LogWriter
The LogWriter
class can be replaced dynamically at any moment with your own implementation in case your goal is to customize the logging behavior. To achieve this, please consider the following steps:
Create a class called
CustomLogWriter
implementing theILogWriter
interface. For example, take a look at the code snippet below:public class CustomLogWriter : cohtml.ILogWriter { public void Log(Net.Severity severity, string message) { UnityEngine.Debug.Log($"Custom {severity}: {message}"); } }
The class must implement the
Log(Severity, string)
method. The first parameter represents theseverity
of the log and the second one contains its content.Then you need to forward the message to Unity3D or your own logging implementation. For this example, we are sending the log to the Unity3D
Console
editor window using theUnityEngine.Debug.Log
method.Now that you’ve created a custom
LogWriter
, assign it to theLogWriter.Writer
static property, which is also used by theLogHandler
. For this example, we will use theStart()
method of aMonoBehaviour
script:public class CustomLogAssigner : MonoBehaviour { public void Start() { LogWriter.Writer = new CustomLogWriter(); LogWriter.Log("Message from Cohtml!"); } }
Attach this class on a scene object of your choice.
Play the game.
You should observe the following output message in the
Console
editor window:Custom Info: Message from Cohtml!