如何仅在 iPhone 应用程序的调试模式下显示日志?
我正在 iPhone Simulator 中调试应用程序。我想仅当应用程序在 iPhone Simulator 中以调试模式运行时显示日志。我正在使用 NSLog
。如何设置 NSLog
的条件,以便日志仅在调试模式下打印在控制台上?
I am debugging the application in iPhone Simulator.I want to show log only when the application is running in debug mode in iPhone Simulator.I am using the NSLog
. How can I put the condition for NSLog
so that the logs should be printed on console in debug mode only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其放入您的
.pch
文件中:现在您可以使用
DLog
而不是NSLog
来处理仅应在调试版本中打印的所有日志消息。人们还可以重新定义 NSLog,但有时您确实希望在设备日志中显示一些日志消息(例如严重错误消息)。
另请参阅 NSLog 替代品的演变,了解如何改进调试日志宏。
Put this in your
.pch
file:Now you can use
DLog
instead ofNSLog
for all log messages that should only be printed in your debug builds.One could also redefine
NSLog
but there sometimes are log messages that you do want to appear in the device logs (like critical error messages).See also The Evolution of a Replacement for NSLog for ideas on how to improve the debug log macro.