Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

iphone - Is there any danger in leaving NSLog statements when building an app for distribution?

For some reason, during my development cycle I find myself deleting NSLog statements that I had inserted to aid in debugging. I don't really know why I have this habit, I just do it.

On occasion, during development I'll find that I'll run into a problem I've had before, and then wind up re-adding an old NSLog statement. And then deleting it again later.

Is there any good reason to delete NSLog statements? From my experience leaving one or two in hasn't caused any app rejection. And since, to my knowledge, they don't log anything anywhere when an app is in distribution (please correct me if I am wrong on this), it doesn't seem like they are harming anything. Is there a performance hit that I should be worried about?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

What I do is add a macro that does the logging only when I am in Debug mode. Put this in your <APP_NAME>_Prefix.pch file

#ifdef DEBUG
#define DebugLog( s, ... ) NSLog( @"<%p %@:%d (%@)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__,  NSStringFromSelector(_cmd), [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DebugLog( s, ... ) 
#endif

As a bonus to the regular log, you get filename, method name, and line number.

Then in the project info, add this under the debug build only. It goes in the User-defined sections under GCC_PREPROCESSOR_DEFINITIONS:

DEBUG

Then replace any of the NSLog's you have in your project with DebugLog (it takes the same args as NSLog) and you won't have to worry about releasing debug statements live.

In answer to your question, logging can slow down the performance of an app and unless you require them for help debugging in the wild, I would leave them out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...