Strip release build from all Debug.Log calls

Hi,

I’d like to know if there’s a way to tell Unity to disable all Debug.Log calls for Android builds. I know there’s “Use Player Log” for PC standalones but this options is not available for Android.

Simple workaround, create your own custom logging class.

And make all log calls to it then don’t do any logging on Android devices.

An easier way - create a custom logger class that uses the ConditionalAttribute over all of its methods.

Logging will be made only when defining the proper compiler define symbol for the logger (ENABLE_LOG).
I actually planned to add a build-time feature that will convert/strip calls to the logger in the final build together with this logger.

If anyone thinks that’s a useful idea i might actually do it and release that to the asset store.

2292960–154242–Logger.cs (2.43 KB)

13 Likes

Try

Debug.unityLogger.logEnabled = false;
2 Likes

Hi.

How is this used in a project? Do I just add it as a script or inside another script and it redirects Debug.Log calls? What about print calls? And how does one set the conditional? Is that internal to Unity’s build mode, or do I have to set it myself?

This one actually worked. Thank you

Works for me thank you. Very surprised at how hard this was to find, definitely more elegant than creating a whole logging class instead of Unity’s just to disable it under certain circumstances.

This is only half the solution.

It still does all the concatenations needed for the call AND performs the call, it’s just that it doesn’t write to the console or to the log file.

To stop the concatenations and the calls from being performed in any non-development build, use the conditional attribute, like @liortal suggested in the post above .

This is a version with all the Debug-methods disabled, unless for Development Builds and Editor, along with the Assertions.

Awesome!!