Rewrite system NSLog ------ macro definition

       During the running of the program, some information is usually printed to help us track the running location, but too many NSLogs in the program are very memory-intensive during the running process, but the user does not need these tracking information when using it.

Disadvantages:

1. Consume mobile phone memory;

2. It is inevitable to leak some sensitive information;

//Rewrite NSLog, print the log and the current number of lines in Debug mode
#if DEBUG

#define NSLog(format, ...) do {                                             \
fprintf(stderr, "<%s : %d> %s\n",                                           \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],  \
__LINE__, __func__);                                                        \
(NSLog)((format), ##__VA_ARGS__);                                           \
fprintf(stderr, "-------\n");                                               \
} while (0)
#define NSLogRect(rect) NSLog(@"%s x:%.4f, y:%.4f, w:%.4f, h:%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
#define NSLogSize(size) NSLog(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
#define NSLogPoint(point) NSLog(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)
#else
#define NSLog(FORMAT, ...) nil
#define NSLogRect(rect) nil
#define NSLogSize(size) nil
#define NSLogPoint(point) nil
#endif

#endif

 [Note] When using the above rewriting method, make sure that the parameters in the following pictures are consistent

The "DEBUG" in the picture is unified with the "DEBUG" in the code .

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326662957&siteId=291194637