Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

How can I see the Unity Debug.Log() output from a running app on the device?

How can I see the Unity Debug.Log() output from a running app on the device? Is there anything like adb logcat (android development)? I have tried using the Logging section of the device portal but not sure if anything will show log entries from the Unity app. Any direction on this will help and it may be something obvious that I have missed.

Tagged:

Answers

  • @MichaelSchenck,
    Debug.Log events will show up in Visual Studio when running with the debugger. If you want to see the logs while in the device, then you'll need to create a display window to show the results in your application.

    Here is a simple (but crude) implementation for showing Debug.Log messages in your application:
    1) Create a new '3D Object > 3D Text' object in your scene
    2) Reset scale (0.1, 0.1, 0.1) and position (0, 0, 2) for comfort
    4) Add the following script to your object for logging messages to the textMesh component:

    using UnityEngine;
    
    public class DebugWindow : MonoBehaviour
    {
        TextMesh textMesh;
    
     // Use this for initialization
     void Start ()
        {
            textMesh = gameObject.GetComponentInChildren<TextMesh>();
     }
    
        void OnEnable()
        {
            Application.logMessageReceived += LogMessage;
        }
    
        void OnDisable()
        {
            Application.logMessageReceived -= LogMessage;
        }
    
        public void LogMessage(string message, string stackTrace, LogType type)
        {
            if (textMesh.text.Length > 300)
            {
                textMesh.text = message + "\n";
            }
            else
            {
                textMesh.text += message + "\n";
            }
        }
    }
    

    Ideally, you would turn the debug window into something that can wrap and auto-scroll the output text. Also, adding a billboard script and/or tagalong functionality would make it more useful in the HoloLens so it doesn't get in the way. Hopefully this is enough to get you started though!

  • Also, if you run with debugging, unity Debug.Log messages will display in the output window in Visual Studio.

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

  • This worked for me, both approaches. The 3D text will display up to about 5 messages at a time.

    To see the messages in the VS output window, set the build to 'Release' but start with debugging (F5).

  • edited January 2018

    Does this still work? I tried creating my own 3d console with Canvas UI and the debug.log messages do appear when I run my app in the Unity Editor but not when I run the app on the Hololens. It seems the Application.logMessageReceived does not get triggered on the Hololens.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class CanvasConsole : MonoBehaviour {

    public Text consoleText;
    private string consoleString;
    
    void OnEnable ()
    {
        Application.logMessageReceived += HandleLog;
    }
    
    void OnDisable ()
    {
        Application.logMessageReceived -= HandleLog;
    }
    
    void HandleLog (string message, string stackTrace, LogType type)
    {
        consoleString = consoleString + "\n" + message;
        consoleText.text = consoleString;
    }
    

    }

  • edited January 2018

    Apparently something in my project was corrupt causing newly created monobehaviour components/scripts in the scene losing their references.

    Something like restarting pc or rebuilding project to new folder seemed to fix this.

    edit: my previous post suddenly got deleted ?

  • I would recommend our new Developer Console asset for this:
    https://assetstore.unity.com/packages/tools/gui/developer-console-132608

    It allows you to view all debug messages in builds, including stacktraces and timestamps, and allows you to collapse duplicates much like Unity's console. It also allows you to specify a custom file to save all debug messages to in an easy to read format.

    It also allows you to turn any public, non-public, static or non-static method into a console command which you can invoke at runtime by simply typing it's name. This also works with parameters and allows you to specify a gameobject as the target.

    Note: It has been developed for PC builds and has not yet been tested on the Hololens, but it just uses Unity's built-in UI system so I see no reason why it shouldn't work. You may just have to change the canvas to world space and re-position it, then add your own input solution to accept Hololens input - this is all I did to get it working correctly in a VR build.

Sign In or Register to comment.