Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Logcat doesn't show Unity Debug.Log() outputs

Discussion in 'Android' started by AnthonyKPR, Mar 15, 2021.

  1. AnthonyKPR

    AnthonyKPR

    Joined:
    Apr 28, 2019
    Posts:
    9
    Hello there,

    Recently I needed to use Android Logcat for some debugging. But to my surprise, I couldn't find a single Unity output. All other ADB Logcat outputs were there, yet unity was failing to show a single output.

    For example I could see outputs with the tags "I/UnityAds" but there was nothing with "*/Unity" tag. I then proceeded to use Unity Android Logcat package instead of the Android Studio Logcat or the ADB Logcat from command line.

    Yet even Unity didn't see its own Debug.Log() outputs in the logcat, but it was showing up on the Unity console outputs. I made an empty project with a script that just screams "POTATO" at me with Debug.Log and I made it turn a cube GameObject on and off to see that the script was working.

    Low and behold, it was working as intended! The console screamed "POTATO" at me, the cube was flickering on and off, yet the Logcat did not give me a single "POTATO" or any Unity tagged outputs.

    Here's the code:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class testDbg : MonoBehaviour
    4. {
    5.     private bool flag = true;
    6.     public GameObject go;
    7.     void Update()
    8.     {
    9.         Debug.Log("POTATO");       // This should scream POTATO at Logcat
    10.  
    11.         go.SetActive(!flag);    //This just visualizes that the code is working
    12.         flag = !flag;
    13.     }
    14. }
    Am I going insane? Isn't this supposed to be working?
     
    dan_ginovker likes this.
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, this should be working. What version of Unity are you using? https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/
     
  3. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
    Could you paste a screenshot for Android Logcat window, just in case.
     
  4. AnthonyKPR

    AnthonyKPR

    Joined:
    Apr 28, 2019
    Posts:
    9
  5. AnthonyKPR

    AnthonyKPR

    Joined:
    Apr 28, 2019
    Posts:
    9
    upload_2021-3-15_22-8-58.png

    Here it is, it stops sending any new logs after the last two warnings, since it is an empty scene with nothing much going on I assume
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Maybe it's not even getting to Update(), can you place similar debug statements in Start() and Awake()? I use a command prompt as in the article I shared using "adb logcat" but they should also show in your output. Also, ensure you attach this script to a game object in your scene.
     
  7. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
    Maybe it's a bug of some sort, what if you do

    Code (CSharp):
    1. adb logcat
    from terminal, without any filters, do you see your messages then?

    What suspicious, is that tag column is empty for PlayerBase::playerBase()

    Also, check Internal Log in logcat window in top right corner, it might show you additional error messages.
     
  8. AnthonyKPR

    AnthonyKPR

    Joined:
    Apr 28, 2019
    Posts:
    9
    The game object is getting turned on and off, which would mean Update() works right?
     
  9. AnthonyKPR

    AnthonyKPR

    Joined:
    Apr 28, 2019
    Posts:
    9
    upload_2021-3-15_23-45-30.png


    Well I see other messages with no filters as you can see and I also opened terminal to do the Command Line logcat and it works as well, its just unity thats not saying anything.
     
  10. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
    Then I guess Android Logcat window behaves as expected, as the same result is displayed by directly invoking adb logcat.

    The question, is why messages are not coming through.
    Did you try selecting Development check box in Build Settings window? Not sure if it will help, but a long shot, since if Development is unchecked, the application is "not debuggable", maybe it affects logging.
     
  11. AnthonyKPR

    AnthonyKPR

    Joined:
    Apr 28, 2019
    Posts:
    9
    Unfortunately it is checked. I am really mind boggled, I tried everything in the book, fresh installing Unity, fresh installing Android studio, outsourcing the adb and putting it in sdk, and the funny thing is everything EXCEPT unity is sending outputs, that's why I am so irritated by it, hope in time a solution will emerge
     
  12. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
    Could you try creating a new empty project with simple script which calls Debug.Log or even Debug.LogError, and see if that changes anything.
    Alternatively, could you try using another phone?
     
  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What was the result when you placed the statements in Start() and Awake()?
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    It works as expected for me. I did Build (vs Build and Run) and then "adb install mybuild.apk" to install on my Samsung Galaxy Edge S7 . Then I ran "adb logcat | findstr -i hello" (I'm on Windows, use grep on Mac) and saw my "Hello from Awake", "Hello from Start", and then a bunch of "Hello from Update". I'm using 2020.1.13f1 but never saw an issue with Unity 2019 either.
     
  15. AnthonyKPR

    AnthonyKPR

    Joined:
    Apr 28, 2019
    Posts:
    9
    I tried that and this is the project I am using as example, I will try using another phone to see if that shakes things up in my favor
     
  16. AnthonyKPR

    AnthonyKPR

    Joined:
    Apr 28, 2019
    Posts:
    9
    Unfortunately didn't work either, will try using a different phone
     
  17. Lancevn

    Lancevn

    Joined:
    Dec 22, 2018
    Posts:
    3
    Use print() instead of Debug.Log(). I have been doing this for years across many projects. This problem is not new to me so I wonder what the setup is for people that say Debug.Log() works. Also, everyone says print is identical to Debug.Log but for me it is not so again, are people making statements without even verifying or is there some setting I'm not aware of?
     
  18. nuClide

    nuClide

    Joined:
    Jun 16, 2017
    Posts:
    4
    upload_2021-10-18_13-42-2.png Screenshot 2021-10-18 141359.png
    Same problem here, everyting works, but Debug.Log.
    Unity version 2020.2.6f1
    Could potentially some scripts intercept Debug.Log and stop it?

    Edit:
    print() or System.Console.WriteLine() doesn't work either
     
    Last edited: Oct 18, 2021
  19. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
    Click on Priority and ensure Verbose is chosen
     
    codestage likes this.
  20. nuClide

    nuClide

    Joined:
    Jun 16, 2017
    Posts:
    4
    It is chosen, but Debug.Log doesn't appear like it was never actually called
    upload_2021-10-18_15-31-30.png
     
  21. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
    Try Opening terminal from Logcat window, and doing manually adb logcat -s Unity, that way it will be clear if it's an issue with Logcat package or something else.
     
  22. unifiedJed

    unifiedJed

    Joined:
    Mar 20, 2015
    Posts:
    9
    I'm struggling with this too. Doesn't work in the logcat window or command prompt....
    I noticed this was initially blank by default though, and this setting hasn't fixed it for me.
    Anyone have any ideas?


    upload_2021-11-9_11-38-37.png
     
  23. unifiedJed

    unifiedJed

    Joined:
    Mar 20, 2015
    Posts:
    9
    The project where it doesn't work was an existing project that I migrated over. I just did a new project and it works, regardless of the settings I posted above.

    Any idea what setting would mess up logging?
     
  24. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
    You're showing Symbol Paths setting, which is used only in Stacktrace Utility, since you're saying it works fine in new project. Check <project>\UsersSettings\AndroidLogcatSettings.asset. You can open it with text editor. You can also delete that file, it will reset logcat settings for that project
     
  25. unifiedJed

    unifiedJed

    Joined:
    Mar 20, 2015
    Posts:
    9
    Not seeing that asset 2020.3.18.... though I do see some related files in the package manager for logcat, will dig around and post if I find a solution
     
  26. unifiedJed

    unifiedJed

    Joined:
    Mar 20, 2015
    Posts:
    9
    In case this helps, there was existing code in my project that disabled / modified how logging is handled to something custom. Can search for these and see if this helps anyone else:

    Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
    OR
    Debug.unityLogger.logHandler = (custom handler here)
     
  27. FlowORemi

    FlowORemi

    Joined:
    Apr 26, 2019
    Posts:
    7
    Maybe You have custom Debug Class that only works for Unity Editor.
    So how about using UnityEngine.Debug.Log instead of just Debug.Log?
     
  28. FunInfused

    FunInfused

    Joined:
    Jun 16, 2021
    Posts:
    16
    If I set the Priority to Debug, I see my Debug.Log() messages.

    If I set it to Verbose, I do not.

    I would expect Verbose would show everything but I guess not. Unclear if that's intended behavior or a bug.
     
    Last edited: Jan 30, 2022
  29. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,635
    search your code to make sure you havent put this somewhere
    Code (CSharp):
    1. Debug.unityLogger.logEnabled=false
     
    RaceCat and anandiamy like this.
  30. Renardjojo

    Renardjojo

    Joined:
    May 15, 2019
    Posts:
    13
    Hi! I miss many logs, including shader compilation, log for me. Ensure you have enabled "full log" toggle in your console
    upload_2022-5-5_17-36-10.png
     
    IsoRegolith likes this.
  31. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    325
    I am having this issue as well, I have tried numerous suggestions,
    I cannot get any Debug.Logs to show in ADB Logcat with any method suggested including through a Terminal and manually filtering.
    I am using Unity Version 2021.3.18f1
     
  32. sh0v0r

    sh0v0r

    Joined:
    Nov 29, 2010
    Posts:
    325
    OK, I go it to work but I have to use 'UnityEngine.Debug.Log' something is screwing with the namespace.
     
  33. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    Same here. There must be something wrong with the logging. I've been using
    Debug.Log()
    all the time and always been able to read the messages from android via adb logcat from the terminal. Since a while it does not work anymore.
    Debug.LogWarning()
    and
    Debug.LogError()
    work as expected.

    I'm using Unity 2021.3.15f1 on a Mac (Silicon). I have had this with some prior version as well.

    I can reproduce it by creating a blank new Project. And adding the following Script:

    Code (CSharp):
    1. using UnityEngine;
    2. public class Test : MonoBehaviour {
    3.     void Start() {
    4.         UnityEngine.Debug.Log("UnityEngine.Debug.Log");
    5.         Debug.Log("Debug.Log");
    6.         Debug.LogWarning("Debug.LogWarning");
    7.         Debug.LogError("Debug.LogError");
    8.     }
    9.  
    10.     void Update() {
    11.     }
    12. }
    13.  
    When deploying on Android and runing adb logcat (from the terminal), only the
    Debug.LogWarning
    and
    Debug.LogError
    get printed. This is similar to what nuClide reported.

    I see all kinds of other Info, Debug, Verbose messages from other packages.

    There is no
    /UserSettings/AndroidLogcatSettings.asset
    in my projects.
     
  34. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    I did some more testing. Same problem with editor version 2019.4.29f1 when trying the script from above. I also tried another machine with version 2021.3.14f1 (also a Mac), same issue.

    I was going to try some more even older versions to get a clue of when the problem might have kicked in. But then I stumbled into the next stupid issue: when trying to create a simple 3D project with editor 2019.2.21f1 (which only has two options, "2D" and "3D") it fails with the error "Failed to resolve project template: [com.unity.template.3d] is not a valid project template.".

    It turns out this is another annoying complication people are struggling with for example here: https://issuetracker.unity3d.com/is...reating-a-new-project-with-2d-or-3d-templates
    It's supposed to be fixed but people still suffer it (including me now).

    Another thought that I had was that it might perhaps be somehow (also) related to or depending on the Android API level being used.

    Maybe it's only on macOS. Nobody really mentions their platform except JeffDUnity3D which is on Windows and not able to reproduce it.
     
    Last edited: Feb 26, 2023
  35. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
    Could you try https://docs.unity3d.com/ScriptReference/Debug.LogFormat.html with first param as LogType.Log, that would be the same as calling Debug.Log
     
  36. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    @Tomas1856 Thanks for responding! If I do

    Code (CSharp):
    1.         Debug.LogFormat(LogType.Log, LogOption.None, this, "Debug.LogFormat Log");
    2.         Debug.LogFormat(LogType.Warning, LogOption.None, this, "Debug.LogFormat Warning");
    3.         Debug.LogFormat(LogType.Assert, LogOption.None, this, "Debug.LogFormat Assert");
    4.         Debug.LogFormat(LogType.Exception, LogOption.None, this, "Debug.LogFormat Exception");
    5.         Debug.LogFormat(LogType.Error, LogOption.None, this, "Debug.LogFormat Error");
    6.         Debug.Log("Debug.Log");
    7.         Debug.LogWarning("Debug.LogWarning");
    8.         Debug.LogError("Debug.LogError");
    I will get

    Unity  W  Debug.LogFormat Warning

    Unity  E  Debug.LogFormat Assert

    Unity  E  Debug.LogFormat Exception

    Unity  E  Debug.LogFormat Error

    Unity  W  Debug.LogWarning

    Unity  E  Debug.LogError


    Log is simply ignored. Only messages with Warning or Error level make it to logcat. I see things like this though

    MONO  I  Getting locale

    Mono  I  Locale en-US


    (These have Info level.)
     
  37. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    It might be worth mentioning that if I run the app in the Unity Editor I will see all messages in the Console panel as expected (Log as well as LogFormat). It is only that when built as an Android app it will loose the basic Log messages.
     
  38. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    I'm just realizing that this only happens when running on a HTC Vive Flow VR headset. On a Pico G2 4K all messages are shown. Will investigate further later.
     
  39. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
  40. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    Interestingly the messages from Java get through.

    When I do

    Code (CSharp):
    1. AndroidJavaClass logClass = new AndroidJavaClass("android.util.Log");
    2. logClass.CallStatic<int>("v", "Test", "Log.v");
    3. logClass.CallStatic<int>("d", "Test", "Log.d");
    4. logClass.CallStatic<int>("i", "Test", "Log.i");
    5. logClass.CallStatic<int>("w", "Test", "Log.w");
    6. logClass.CallStatic<int>("e", "Test", "Log.e");
    7. Debug.Log("Debug.Log");
    8. Debug.LogWarning("Debug.LogWarning");
    9. Debug.LogError("Debug.LogError");
    I get

    Test   V  Log.v

    Test   D  Log.d

    Test   I  Log.i

    Test   W  Log.w

    Test   E  Log.e

    Unity  W  Debug.LogWarning

    Unity  E  Debug.LogError
     
  41. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    The developer settings on the HTC Vive Flow are rather spartanic. There is only "USB debugging" (on/off) and "OEM unlock" (on/off).
     
  42. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    I tested building the app with Android Target API Level 28 instead of 29.
    Debug.Log
    messages are still ignored.
     
  43. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    lvwxu likes this.
  44. thejox

    thejox

    Joined:
    Sep 29, 2015
    Posts:
    12
    One last note. Before setting the prop to
    DEBUG
    I was reading it with

    adb shell getprop log.tag.Unity


    and what I got was

    WARN


    and it will be
    WARN
    again after each reboot.
     
  45. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,933
    Wow, good find, thanks for sharing, didn't know you can limit logging like that.
     
    GorasGames likes this.