Using ARDK Logging

ARDK has built-in logging features for most ARDK classes. Enable logging while you develop your AR experience to help debug, diagnose internal ARDK state, understand ARDK object lifecycle, and more.

Enabling ARDK Logging

Note

Debug logging can produce a large number of log messages that might impact performance, so you should remove ARDK_DEBUG before building the release version of your app.

To develop with ARDK logging, first define the ARDK_DEBUG symbol which enables debug-level logging. Navigate to Edit > Project Settings > Player. Then in the Other Settings panel, scroll to Script Compilation. Under Scripting Define Symbols, press + and add ARDK_DEBUG.

Then, in the initialization code of one of the scripts in your project, use ARLog to call ARLog.EnableLogFeature(). You’ll typically add this to your script’s Awake() or Start() method. If you’re using Unity development builds, you can wrap your call to ARLog.EnableLogFeature() in a #if DEVELOPMENT_BUILD conditional if you only want logging in your development builds.

You’ll need to specify the ARDK namespace or class that you want to generate log information for. For example, if you want to generate logs for all classes and namespaces in the Niantic namespace, you’d call ARLog.EnableLogFeature("Niantic").

The following example enables logging for classes in the Niantic.ARDK.VirtualStudio namespace.

using Niantic.ARDK.Utilities.Logging;

public class MySceneScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        // Enable ARDK logging
        ARLog.EnableLogFeature("Niantic.ARDK.VirtualStudio");

        // ...other initialization code
    }
}

Capturing Log Information

ARDK’s default log handler sends messages to Unity’s Debug.Log when logging is enabled. When you run your app in Mock Mode or Remote Mode, you’ll see ARDK log messages in the Unity console.

#Niantic.ARDK.VirtualStudio._VirtualStudioManager#: VirtualStudioMaster Initialized.
UnityEngine.Debug:Log (object)
#Niantic.ARDK.AR.Configuration.ARSessionChangesCollector#: Registered Niantic.ARDK.Extensions.ARDepthManager as ARConfigChanger.
UnityEngine.Debug:Log (object)
...

If you need to output log messages to a custom log handler, you’ll need to create an implementation of IARLogHandler and set ARLog.Loghandler to an instance of your custom log handler. The following example demonstrates a simple custom log handler.

using Niantic.ARDK.Utilities.Logging;

public class CustomLogHandler : IARLogHandler
{
    // Gets the singleton instance of this log handler.
    public static readonly CustomLogHandler Instance = new CustomLogHandler();

    private CustomLogHandler()
    {
    }

    // ...implement Debug(), Warn(), Release(), Error() as needed...
}

In your code where you enable logging, set the custom log handler.

void Start()
{
    // Set custom log handler
    ARLog.LogHandler = CustomLogHandler.Instance;
    // Enable ARDK logging
    ARLog.EnableLogFeature("Niantic");
}