Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Does Application.logMessageReceivedThreaded receive msgs when Debug.unityLogger.logEnabled == false?

Discussion in 'Scripting' started by jgmakes, Jan 11, 2021.

  1. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    75
    Does turning off the Debug.unityLogger suppress the messages that would be caught by delegates of Application.logMessageReceivedThreaded? I'm hoping not.

    I want to be able to grab all Exceptions (via Application.logMessageReceivedThreaded) so I can send/log them to my server but I also want to turn off general Debug.Logs (via Debug.unityLogger.logEnabled = false) that would clutter up the production build on users' devices. I don't see any documentation on how the two interact, if at all.

    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    If it ain't in the docs, I imagine you could make an experiment in less time than I could. :)
     
  3. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    75
    :)

    I don't see any mention of a relationship in the docs.

    And it seems as though logEnabled = false does in fact suppress logMessageReceivedThreaded msgs, which at least for my purposes is unfortunate.

    I guess I'm curious if there is another way to go about getting my desired result...
    1. I want centralized access to any Exceptions that might have been missed... or that are located in code I didn't write... so that I can log anything hitting my production users to, in this case, Crashlytics.
    2. I don't want users devices getting hit with errant Debug.Log statements that would either slow down performance or highlight any kind of data not meant for their eyes.
     
  4. dorinoltean

    dorinoltean

    Joined:
    Jun 24, 2020
    Posts:
    1
    I integrated NLog in my unity app. And I have an NLog Target that writes to unity, and an NLog Target that logs to file, and i can enable / disable each target. You can easily write a target that centralizes your logs

    With logMessageReceivedThreaded I experienced delays in some setups.


    Code (CSharp):
    1. using NLog;
    2. using NLog.Targets;
    3. using UnityEngine;
    4.  
    5. namespace Altom.AltUnityDriver.Logging
    6. {
    7.     /// <summary> An appender which logs to the unity console. </summary>
    8.     public class UnityTarget : TargetWithLayout
    9.     {
    10.         public UnityTarget(string name)
    11.         {
    12.             this.Name = name;
    13.         }
    14.         /// <inheritdoc />
    15.         protected override void Write(LogEventInfo logEvent)
    16.         {
    17.             string message = this.Layout.Render(logEvent);
    18.  
    19.             if (logEvent.Level >= LogLevel.Error)
    20.             {
    21.                 // everything above or equal to error is an error
    22.                 Debug.LogError(message);
    23.             }
    24.             else if (logEvent.Level >= LogLevel.Warn)
    25.             {
    26.                 // everything that is a warning up to error is logged as warning
    27.                 Debug.LogWarning(message);
    28.             }
    29.             else
    30.             {
    31.                 // everything else we'll just log normally
    32.                 Debug.Log(message);
    33.             }
    34.         }
    35.     }
    36.  
    37. }