Suppressing Noisy Log Output (NSLog)

Introduction I was logging delegate method calls to observe the call order, only to find my console flooded with completely unrelated log messages. I couldn't stand it anymore. About is defined as: In most cases, to suppress debug logs in production, we replace with a macro: Or a more detailed version: is a variadic macro — not widely known, but it was introduced in the C99 standard. The prefix before serves to strip the preceding comma when no variadic arguments are passed, preventing compilation errors. is replaced by the current source file name at preprocessing time. is replaced by the current line number at preprocessing time. is replaced by the current function name at preprocessing time. Replacing About and Since C doesn't support function overloading, handling variable numbers of function arguments is more involved. In a process, the stack grows from high to low addresses. When a function is called, its argument list is pushed onto the high-address portion of the stack, followed by the return address, then the function's executable code. The stack address decrements throughout this process. (Some exploits work by modifying the return address on the stack to redirect execution to injected code.) Here's an illustration: In plain terms: sets to point to the argument after (the second argument to must be the parameter immediately before , in order to locate the first variadic argument). retrieves the variadic argument of the given type and advances to the next argument. Finally, resets for robustness. So in practice, you'd add an extra argument: — this allows the message to print. Calls without the argument will be filtered out. Although this works in a test project, it keeps breaking when applied to a real project. Two days of debugging and I still couldn't get it working. This approach appears to be a dead end. Macro Replacement The final approach is to modify the macro in the prefix header file, replacing it entirely with a macro that only prints when the log string starts with : Miscellaneous If your project uses , just commenting out will do. At this point, most LLDB output is gone. There may still be some logs from third-party SDKs, but they're much less distracting.