Log Handler
On this page
Overview
The Prysm integration in Unity3D logs all messages inside built-in Unity3D editor console. This helps you understand what the state of the Prysm 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!
Debug
or Trace
.How to use
To set up a LogHandler with a custom LogWriter
:
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}"); } }
CustomLogWriter
must implement theILogWriter
interface.Implement the method
Log(Severity, string)
. The first parameter is theseverity
of that message and the second is thecontent
of the message.For that example, the method contains a simple log on the Unity3D editor console.
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!") } }
Attach that class anywhere you want on the scene objects.
Disable the component.
Play the game.
Enable the component.
The output message will be:
Custom Info: Message from Cohtml!