Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
11
Question by ercion · Jan 19, 2017 at 04:34 PM · androiddebug.logreleaselogginglogcat

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RobAnthem · May 06, 2017 at 05:03 PM 0
Share

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

5 Replies

· Add your reply
  • Sort: 
avatar image
17

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ercion · May 06, 2017 at 09:27 AM 0
Share

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.

avatar image tjPark · Aug 07, 2019 at 03:51 PM 2
Share

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
 
avatar image
17

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ercion · May 06, 2017 at 09:10 AM 0
Share

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.

avatar image Oliver-Bogdan · May 06, 2017 at 05:41 PM 0
Share

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.

avatar image sgrein · Jan 23, 2020 at 11:15 PM 0
Share

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")]?

avatar image
3

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.

alt text


log-options.png (28.9 kB)
uselog.png (22.9 kB)
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ercion · Jan 20, 2017 at 09:14 AM 0
Share

Thanks for replying. Sorry I forgot to mention that I've already done that with no avail.

logging

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:

app log

app-log.png (35.7 kB)
avatar image asafsitner ercion · Jan 20, 2017 at 10:59 AM 0
Share

You are correct. Updated the answer after reading the documentation again. I knew it was there somewhere xD

avatar image ercion asafsitner · Jan 20, 2017 at 11:40 AM 0
Share

The option does not seem to be available for Android :(

avatar image
1

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


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to read Debug.Log when using Android? 3 Answers

Android Logcat for Unity3D Debugging 1 Answer

Keep getting AudioTrack messages when I use Android logcat with my unity app. 0 Answers

How to remove all unity's debug output from Android 1 Answer

What is TA Load in the Android internal profiler? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges