Pretty sure the answer is “no”, but is it possible to disable all logging when making final release builds? We could of course go through our game and remove/disable all the Debug.logs that we create, but we’re using a lot of plugins and DLLs that have their own logs, and Unity itself prints some things to the log.
The trick is, whenever there’s a Debug.log it seems to open the log file, write something like 10 lines to it (call stack for the Debug.log), then close it. On certain devices (like iPhone) this is a slow process that can cause framerate issues, and I wouldn’t be surprised if the file can get large enough to start affecting memory as well. And the log isn’t really all that useful to us in release builds, unless we can convince a user to go through all the steps to pull it from the device and send it to us.
The Application class has a static LogCallback delegate and 2 LogMessageReceived events to listen for. I’m not sure if you can disable debug logs, but it’s likely through either the Debug or Application class.
What I would do in your situation is make your OWN log class so you can call MyDebug.Log() and pass the results from there to the normal Debug.Log() unless you toggle a “ReleaseBuild” bool. Once you write that class, all you need to do is a “Find&Replace All” for your whole project, replacing Debug.log with MyDebug.Log().
Yeah write your own wrapper and flag the method with System.Diagnostics.ConditionalAttribute Technical documentation | Microsoft Learn. Use either one of unitys conditionals or create your own. That way the compiler schould remove all calls to the method
Unfortunately, that doesn’t really help me, because I don’t want to remove Debug.Logs, I want them to just not write to the log file in release builds, something that should in theory be an easy thing for the Unity guys to implement. Because as I said, we use a LOT of plugins, I don’t want to edit code in plugins, also some Debug.logs are hidden in DLLs, and Unity itself writes data to the console (and thus the log file), even in release builds. We actually created our own DebugLog class long ago (that unfortunately not everyone used in the long time since we started the project), but that doesn’t completely solve the problem.
Dunno about Android, but at least on iOS, every Debug.Log is written to a log file, which is why having lots of Debug.Logs can really kill the framerate, as it is accessing the file system. And I’m assuming it affects memory as well, since it has to open this file which could get rather large after an extended play session.
If you want logging dependent on development/release build or platform depending “You can also use the DEVELOPMENT_BUILD #define directive to identify whether your script is running in a player which was built with the “Development Build” option enabled.” (Source: Unity - Manual: Conditional compilation)
The option can be en- or disabled: "In the Build Settings dialog there is a check box called “Development Build”. (Source: Unity - Scripting API: Debug).
And all together for development or release builds #if DEVELOPMENT_BUILD Debug.logger.logEnabled=true; #else Debug.logger.logEnabled=false; #endif
… or different platforms: #if UNITY_EDITOR Debug.logger.logEnabled=true; #elseif UNITY_IPHONE Debug.logger.logEnabled=false; #elseif UNITY_STANDALONE_OSX Debug.logger.logEnabled=false; #endif
Hi,
I know its an old forum. But I had a doubt regarding disabling logs. if we disable logs "Debug.logger.logEnabled=false;", will it only disable the displaying of logs or will it disable the logs internally?
Basically, is "Debug.logger.logEnabled=false;" equivalent to removing all the log statements in your scripts manually?
To answer your question: It’s not equivalent to removing the statement because the method is still called. This means that any string concatenations, etc in the parameter list will still be executed too.