- Home /
How to disable all logging on release build?
I've just released this game on Play Store (Mr. Frump) and I noticed that the debug logs are still there. I've removed all the logs in my scripts but I'm using a few plugins that log stuff as well. I'm trying to disable all logging on release build and getting nowhere.
After 8 hours, I only found that everyone on Unity forums and on SO suggests either calling Debug.Log with in a preprocessor section or stripping Log function calls with ProGuard.
I find that the first approach is naive considering one does not log errors and assertions oneself.
Since I'm a newbie to ProGuard, second approach led me nowhere. My app crashed on launch with every ProGuard configuration I could do and the logs didn't help either.
Every time something gets logged, frame rate drops. I'm pulling my hair here and I'd appreciate any help possible.
Thanks.
$$anonymous$$y best suggestion is Debug logging is meant for debugging, there is literally no reason to leave the code inside your class files once you accomplished the debugging process. Logging should only be done when there is a problem and you need to figure out what is going on.
Answer by Syameshk · May 04, 2017 at 07:01 AM
Hi,
You can disable it from any script at any point of the time.
#if UNITY_EDITOR
Debug.logger.logEnabled = true;
#else
Debug.logger.logEnabled = false;
#endif
Hi, thanks for the reply Syameshk! I've tried this before, it solved half of my problem. I wrote it in Awake of a script that is first in execution order. It works fine for the logs of scripts, but Unity writes logs right in the beginning before any script executes. Those logs can still be seen in adb. See my comment on asafsitner's reply.
This "Debug.logger" changed as "Debug.unityLogger" from some new version. so,, in the recent version Unity, attach below:
#if UNITY_EDITOR
Debug.unityLogger.logEnabled = true;
#else
Debug.unityLogger.logEnabled=false;
#endif
Answer by Oliver-Bogdan · May 04, 2017 at 08:39 AM
According to the Unity Documentation relating Best Practice you should wrap development-only logging calls in custom methods and decorating that method with the [Conditional] attribute.
#define ENABLE_LOGS
public static class Logger {
[Conditional("ENABLE_LOGS")]
public void Debug(string logMsg) {
Debug.Log(logMsg);
}
}
If none of the defines passed to the Conditional attribute are defined, then the decorated method and all calls to the decorated method are compiled out. The effect is identical to what would happen if the method and all calls to the method were wrapped in #if … #endif preprocessor blocks.
https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity7.html
Hi Oliver. Thanks for the reply! Your method works fine with the log calls that I'd make. But unfortunately it doesn't solve my problem as Unity and plugins write logs themselves, as you can see in my comment to asafsitner's reply. This approach will probably not strip their logs out.
You are welcome. Yes, this approach would not strip those logs. I think it's mandatory that plugin writers would give an option to disable logs, something like VERBOSE OFF.
Will calls to UnityEngine.Debug.Log("") be filtered out during building a release? Or would I still have to wrap this method and decorate with [Conditional("ENABLE_LOGS")]?
Answer by asafsitner · Jan 19, 2017 at 07:52 PM
EDIT: I remembered it was there, but not the correct section. :)
According to the Unity Documentation, you need to untick the option Use Player Log
in Resolution and Presentation
Check this box to write a log file with debugging information. If you plan to submit your application to the Mac App Store, leave this option un-ticked. Ticked is the default.
Thanks for replying. Sorry I forgot to mention that I've already done that with no avail.
I've also tried the following code:
#if DEVELOP$$anonymous$$ENT_BUILD
Debug.logger.logEnabled=true;
#else
Debug.logger.logEnabled = false;
#endif
Following is the some of the log I still see:
You are correct. Updated the answer after reading the documentation again. I knew it was there somewhere xD
The option does not seem to be available for Android :(
Answer by omar92 · Mar 18, 2021 at 04:31 PM
you better use (Tested on Unity2019.4)
#if !(DEVELOPMENT_BUILD || UNITY_EDITOR)
Debug.unityLogger.filterLogType = LogType.Exception;
#endif
or use
#if !(DEVELOPMENT_BUILD || UNITY_EDITOR)
Debug.unityLogger.logEnabled = false;
#endif
Answer by prasetion · Oct 01, 2021 at 03:06 AM
Maybe try to export into android studio first if your target is android. Then change build variant into release. If it is not solve the issue, try to use custom proguard, in unity 2020, you can check in build settings -> custom proguard. For the detail you can check my article here
https://prasetion.medium.com/remove-all-log-unity-app-in-android-e5e0f3529569
hope solve the issue