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

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!

If it ain’t in the docs, I imagine you could make an experiment in less time than I could. :slight_smile:

:slight_smile:

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…

  • 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.
  • 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.

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.

using NLog;
using NLog.Targets;
using UnityEngine;

namespace Altom.AltUnityDriver.Logging
{
    /// <summary> An appender which logs to the unity console. </summary>
    public class UnityTarget : TargetWithLayout
    {
        public UnityTarget(string name)
        {
            this.Name = name;
        }
        /// <inheritdoc />
        protected override void Write(LogEventInfo logEvent)
        {
            string message = this.Layout.Render(logEvent);

            if (logEvent.Level >= LogLevel.Error)
            {
                // everything above or equal to error is an error
                Debug.LogError(message);
            }
            else if (logEvent.Level >= LogLevel.Warn)
            {
                // everything that is a warning up to error is logged as warning
                Debug.LogWarning(message);
            }
            else
            {
                // everything else we'll just log normally
                Debug.Log(message);
            }
        }
    }

}