是否可以使用 NSLog 语句提交 iPhone 应用程序二进制文件?

发布于 2024-08-20 05:27:31 字数 152 浏览 6 评论 0原文

我即将提交我的第一个 iPhone 应用程序。

我已经放置了大量 NSLog 语句来测试和调试应用程序。

所以我的问题是“是否可以将 NSLog 语句保留在源代码中”

并且我怀疑 nslog 语句是否会减慢总执行时间。

谢谢。

I am just about to submit my first iPhone app.

I have put lots of NSLog statements to test and debug the application .

So my question is " Is it ok to keep the NSLog statements in the source code "

and I have a doubt that whether the nslog statements slows down the total execution time or not .

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

维持三分热 2024-08-27 05:27:31

我一直在使用这个(在某个地方找到的):

// DLog is almost a drop-in replacement for NSLog to turn off logging for release build
// 
// add -DDEBUG to OTHER_CFLAGS in the build user defined settings
//
// Usage:
//
// DLog();
// DLog(@"here");
// DLog(@"value: %d", x);
// Unfortunately this doesn't work DLog(aStringVariable); you have to do this instead DLog(@"%@", aStringVariable);
//

#ifdef DEBUG
#   define DLog(__FORMAT__, ...) NSLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#   define DLog(...) do {} while (0)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(__FORMAT__, ...) NSLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

Facebook 的 Three20 项目有更复杂的调试或日志记录方式。

I used this all the time (found it somewhere):

// DLog is almost a drop-in replacement for NSLog to turn off logging for release build
// 
// add -DDEBUG to OTHER_CFLAGS in the build user defined settings
//
// Usage:
//
// DLog();
// DLog(@"here");
// DLog(@"value: %d", x);
// Unfortunately this doesn't work DLog(aStringVariable); you have to do this instead DLog(@"%@", aStringVariable);
//

#ifdef DEBUG
#   define DLog(__FORMAT__, ...) NSLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#   define DLog(...) do {} while (0)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(__FORMAT__, ...) NSLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

The three20 project from Facebook has more complex way to debug or logging.

憧憬巴黎街头的黎明 2024-08-27 05:27:31

我之前开发的一个应用程序有许多 NSLogs 将调试转储到控制台。我们发现它们极大地影响了 iPhone 3G 的性能。 3GS 上的性能下降很明显,但没有那么严重。

我的建议是使用预处理器宏和调试预处理器定义来有条件地在调试版本中使用 NSLogs,但不在发布版本中。

An app I was working on perviously had many NSLogs dumping debug to the console. We found that they hindered performance drastically on the iPhone 3G. The performance hit was noticeable on a 3GS, but not as much.

My advice would be to use a preprocessor macro and a debug preprocessor definition to conditionally use NSLogs in debug builds but not in release builds.

╰沐子 2024-08-27 05:27:31

我在 AppStore 上的三个应用程序都加载了 NSLogs,所以我想没关系......

The three apps I have on the AppStore are loaded with NSLogs so I guess it's okay...

一枫情书 2024-08-27 05:27:31

我从来没有摆脱过我的:)

有些人建议使用条件编译/编译器宏,这样你就可以在没有任何 NSLog 的情况下进行构建,但我认为这付出了太多的努力而回报却很少。

但是,NSLog 确实会(稍微)减慢应用程序的速度,因此我会删除任何直接影响性能的日志。另外,您可能想删除一些调试日志记录信息以隐藏您如何实现应用程序等。

希望这有帮助,

Sam

I've never got rid of mine :)

Some people recommend conditional compiling / compiler macros so you can make a build without any NSLog at all but I think that's too much effort for very little reward.

However, NSLogs do slow the app down (slightly) so I'd remove any ones that are directly affecting performance. Also, you might want to remove some debugging logging information to hide how you have implemented your app etc.

Hope that's helpful,

Sam

南街女流氓 2024-08-27 05:27:31

XCode4 对此提供了一个非常简洁的解决方案 - 使用断点。
选择操作“记录消息”并将 val = @val@ 设置为消息,
然后勾选“评估操作后自动继续”框。

并不适合所有用例,但它可以为您带来轻松“检查”的好处
的价值观和保证,他们不会将其放入版本中。

XCode4 offers a pretty neat solution to this - use breakpoints.
select action 'log a message' and set val = @val@ as the message,
then tick the 'automatically continue after evaluating actions' box.

Won't fit every use case, but it gives you the benefit of easy 'inspecting'
of values and guarantees they won't make it into a release.

霞映澄塘 2024-08-27 05:27:31

我只是使用存储在 userPrefs (plist) 中的“useDebugMode”单例 int 设置为 0 或 1。并且,根据 iPhone 的 UUID,我在设置屏幕上添加了“使用调试模式:开/关”切换,以便我可以在将来使用生产版本调试问题。如果人们将来抱怨程序问题,这使我能够调试数据问题(使用下载的 XML)。然后,我将所有“NSLog”和“printf”包装在

if (useDebugLog == 1)
{
     NSLog(@"debug statement");
}

这对我有用...当然,:

 if (useDebugLog == 1)

导致一些开销,我愿意处理。

I simply use a "useDebugMode" singleton int set to 0 or 1 that is stored in userPrefs (plist). And, depending on the UUID of the iphone, I add a "Use Debug Mode: on/off" toggle to the settings screen so i can debug problems in the future with production versions. This allows me to debug data problems (with downloaded XML) if people complain about issues with the program in the future. I then wrap all "NSLog"s and "printf"s in

if (useDebugLog == 1)
{
     NSLog(@"debug statement");
}

This works for me...Of course, the:

 if (useDebugLog == 1)

causes some overhead that I am willing to deal with.

戈亓 2024-08-27 05:27:31

在Release中使用NSLog不是问题。但是,如果您将任何有价值的数据放入日志中,其他用户(开发人员)就可以看到该数据。比如一些下载链接等等。

Its not a problem of using NSLog in Release. But if you put any valuable data in log other user(developer) can see that data. Like some download link etc..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文