Log Handler

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!

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:

  1. Create a class called CustomLogWriter implementing the ILogWriter 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}");
        }
    }
    
  2. The class must implement the Log(Severity, string) method. The first parameter represents the severity of the log and the second one contains its content.

  3. 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 the UnityEngine.Debug.Log method.

  4. Now that you’ve created a custom LogWriter, assign it to the LogWriter.Writer static property, which is also used by the LogHandler. For this example, we will use the Start() method of a MonoBehaviour script:

    public class CustomLogAssigner : MonoBehaviour
    {
        public void Start()
        {
            LogWriter.Writer = new CustomLogWriter();
            LogWriter.Log("Message from Cohtml!");
        }
    }
    
  5. Attach this class on a scene object of your choice.

  6. Play the game.

  7. You should observe the following output message in the Console editor window:

    Custom Info: Message from Cohtml!