I would like to know how many types od log are there and when to use what type log .Till now i have been using NSLog but when i finally submit the applcation to开发者_如何学运维 app store i need to search for the nslog and need to close them all .I have heard of Dlog , Alog but dont know how to use.So is there any solution which would set Log off when we select release, debug modes.It would be great if yuo can provide me a code for diffent Log types and how to use them.
You can define project-wide macros in your <project>.pch
file. For example:
#if DEBUG
#define DLog(format, ...) NSLog((format), ## __VA_ARGS__)
#else
#define DLog(format, ...)
#endif
(This assumes you're setting the DEBUG macro in your debug builds: Is there a macro that Xcode automatically sets in debug builds?)
Then you can use DLog
anywhere you've used NSLog
for messages that should only appear in your debug builds, in your release builds they will be gone.
More sophisticated versions can be found in the answers to the question: How to print out the method name and line number and conditionally disable NSLog?
Also, you could roll your own logging class.
I think you are trying to turn off NSLogs in your final build. Here is a solution that has been posted before:
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
精彩评论