I’ve been looking through the realtime logs of an iOS release build of my Unity mobile game (i.e., the build did not have “Development Build” checked). I couldn’t find the log message that I was looking for, even though that code path was definitely executing. It occurred to me that Unity might be stripping informational logs from release builds (i.e., with LogType.Log), or else conditionally not printing them. However, I am seeing other informational logs, and it seems entirely inconsistent. Regardless of assembly or type, some log messages are showing up in the iOS realtime logs, while others are not. In fact, some informational logs are printing, while some Warning messages or not, so there doesn’t seem to be any LogType-based filtering happening.
Has anyone else observed this behavior? I’m okay with informational logs not printing in release builds for performance reasons, but why are some printing and others not, seemingly at random? And how would informational logs print but not warnings? Is there like a log throttling mechanism within release builds?
It’s an interesting question. I’ve seen the behavior change over the years of using Unity so I’m not sure where it stands. Perhaps what is shown is dependent not only on log level (notice, warning, error), but also subsystem, eg., from your scripts versus something in the engine core?
I have been on many projects that aggressively wrap Debug.Log() with their own system so they can be confident that all of their script logging is disabled in release builds. It has never materially improved the project, because invariably when there is a crash in release, it just keeps you from seeing what happened easily, dragging out the debugging time.
I consider such coding to be naively-ham-fisted over-engineering. The bulk of the benefit could come from just removing per-frame logging and leave in the init / deinit logging, which is often where our scripts choke up anyway. It’s not as bad as pokemon try/catch exception handling, which is its own special misery if you ever have to deal with it in a project!
ALSO: the editor wraps a bunch of stuff and throws different errors, such as Missing Reference and Unassigned Reference errors, which most of the time blow up as a Null Reference Exception in a non-editor actual build.
Yeah I very consciously did not want to implement my own logging system lol. I’m essentially using Serilog, with a custom Unity sink. I set Serilog’s LoggerConfiguration.MinimumLevel to the equivalent of Unity’s Debug.unityLogger.filterLogType.
I agree with all your best practice thoughts. I don’t use any per-frame logging and I try to stick with event-based logs (“Starting operation X” and “Operation X completed” type stuff), and I always leave Informational logs and above enabled to help with debugging. I use Unity Analytics and they actually show the most recent logs alongside analytics events, which can be helpful. I do try to follow .NET’s high-performance logging setups wherever possible though, to eek out a little extra performance by not parsing log messages during every call, e.g.
I had that thought, but the logs are inconsistent even among my scripts. In one case, I have a Bootstrapper class that runs at app startup, logging a bunch of times as it sets up various systems, but only one of these messages is printing, even though all the others are being logged the same way.
Interesting. I don’t think that’s relevant to this logs-sometimes-being-printed issue, but good to know.
Also I’ve never heard “pokemon exception handling” lol; I love that. “Gotta catch em all”
FWIW this seems a recurring problem but only on mobile. I guess the idea here is to keep things responsive in case an application logs too aggressively. Perhaps it may also have to do with thread congestion, especially if you view live logs transferred from the device and shown to you (ie in Xcode). Did you search through the actual log file or some log viewer?
In release builds there may also be stripping happening, but only if the log is in a method flagged with the [Conditional] attribute.
Haven’t heard of this before. But makes total sense: “Gotta catch 'em all!”
I suppose this refers to catch-all exception handling and possibly not even logging it.
I’ll flag this for spam, not because of you but because this website seems potentially harmful. There’s no legally identifiable information to be found ie nobody knows who that company or individual is. It’s also pretty much a violation of law around the globe if their tools are sold internationally.
Perhaps use a tool suited for the job? Xcode should show you live logs, and then there’s ADB and even though that’s a command prompt tool, I’m betting there exists some form of UI for it if only to show the live logs.
@CodeSmile That seems excessive. 3uTools is a pretty well-known tool; I’ve come across numerous forums/articles/tutorials about it, and the application feels quite solid and well-designed. I agree it’s sus that there’s no company name on the website and their About Us page lists a Gmail email, but the application itself has an About screen with the company name “Shenzhen Aidapu Network Technology Co.,Ltd.” and a full EULA and Privacy Policy. They’re a Chinese company so maybe that’s why their website is a little atypical; idk. All in all I’ve had no issues with 3uTools over the last year, and I see no reason to consider it or its website harmful (other than the general twitchiness that a Westerner might get when hearing that an application is Chinese).
I do use ADB for Android (with Unity’s Android Logcat package) but Xcode requires a Mac, which I do not have. Once upon a time, I googled “view ios logs on windows” and 3uTools was the first tool that came up.