iOS custom output with macros (NSLOG)

Source: Internet
Author: User

Objective:

1) output log is a large loss of system performance

2) The information that is output is easily intercepted, causing the information to be unsafe.

So we're going to cancel all of the logs in the release version (release). It is obviously not a clear choice if you are going to comment out the log one line at a line.

So we can use macros to customize the log output.

One of the simplest examples:

#ifdef debug# define Gclog (FMT, ...) NSLog (FMT), # #__VA_ARGS__); #else # define Gclog (...); #endif

How to use:

Gclog (@ "sdf");

Using macros to customize the output, you can also easily manage the content of the output:

#ifdef DEBUG  # define DLOG (FMT, ...) NSLog (@ "[filename:%s]\n""[function name:%s]\n""[line number:% D] \ n"FMT"  , __file__, __function__, __line__, # #__VA_ARGS__)  ; #else  # define DLOG (...);   #endif  

Excerpt from: http://blog.csdn.net/remote_roamer/article/details/7107320

1)  __VA_ARGS__ is a variable-parameter macro that few people know about this macro, which is the new C99 specification, and currently appears to be supported only by GCC (VC6.0 compiler does not support it). The macro front Plus # #的作用在于, when the number of variable parameters is 0 o'clock, here the # #起到把前面多余的"," Remove the effect, otherwise it will compile error, you can try.  2) __FILE__ macro will be replaced with the current source file name at the time of precompilation 3) __LINE__ macro will be replaced with the current line number 4 at precompilation __FUNCTION__ macros will be replaced with the current function name at the time of precompilation. With these macros, especially with __va_args__, the output of debug information becomes much more flexible. 

Excerpt from: http://blog.chinaunix.net/uid-22878837-id-2110544.html

iOS custom output with macros (NSLOG)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.