Log Handler

Overview

The Gameface integration in Unity3D logs all messages inside built-in Unity3D editor console. This helps you understand what the state of the Gameface plugin is. Detailed implementation you can see in CohtmlPackage/Runtime/Cohtml/Detail/Logging/LogHandler.cs

Custom LogWriter

You can change the LogHandler’s LogWriter dynamically with custom and operate with the coming messages your way. You can set a custom implementation of LogWriter at any moment. The default implementation of the cohtml.LogWriter is located in CohtmlPackage/Runtime/Cohtml/Detail/Logging/LogWriter.cs and it uses the format:

[Cohtml] (Info) Message from Cohtml!

How to use

To set up a LogHandler with a custom LogWriter:

  1. Create a class called CustomLogWriter for the example. It looks like the code below:

    public class CustomLogWriter : cohtml.ILogWriter
    {
        public void Log(Net.Severity severity, string message)
        {
            UnityEngine.Debug.Log($"Custom {severity}: {message}");
        }
    }
    
  2. CustomLogWriter must implement the ILogWriter interface.

  3. Implement the method Log(Severity, string). The first parameter is the severity of that message and the second is the content of the message.

  4. For that example, the method contains a simple log on the Unity3D editor console.

  5. To use your class, you can use the static property LogHandler.Writer.

    public class CustomLogAssigner : MonoBehaviour
    {
        private void OnEnable()
        {
            LogHandler.Writer = new CustomLogHandler();
            LogHandler.Log("Message from Cohtml!")
        }
    }
    
  6. Attach that class anywhere you want on the scene objects.

  7. Disable the component.

  8. Play the game.

  9. Enable the component.

  10. The output message will be:

    Custom Info: Message from Cohtml!