IOS development: Log with higher code positioning and ioslog
Master haomeng is devoted to his contribution and respects the author's Labor achievements. Do not repost them.
If the article is helpful to you, you are welcome to donate to the author, support haomeng master, the amount of donation is free, focusing on your mind ^_^
I want to donate: Click to donate
Cocos2d-X source code download: point I send
Game official download: http://dwz.cn/RwTjl
Game video preview: http://dwz.cn/RzHHd
Game Development blog: http://dwz.cn/RzJzI
Game source code transfer: http://dwz.cn/Nret1
For Log, printing the current FUNCTION is nothing more than _ cmd, _ func __, _ FUNCTION __, _ PRETTY_FUNCTION __. in Xcode, _ cmd returns a SEL object,
The rest are definitions from the C/C ++ compiler, so a C string is returned, and the results are similar. Different compilers may have slight differences.
Obviously, the _ func _ series are easier to use than the _ cmd series. Compared with method calls in the Objective-C type,
It not only displays the method name, but also shows the type, with _ LINE __, you can precisely locate the location of Log in the code.
For example:
@ Implementation MyClass + (void) doo {// _ func __, _ FUNCTION __, _ PRETTY_FUNCTION _ are similar to NSLog (@ "Method: % s, Line: % d. ", _ func __, _ LINE _);} @ endOutput:
Method: + [MyClass doo], Line: 16.
We can also define some macros for quick use in NSLog or other Log frameworks, such:
#define FUNCINF [NSString stringWithFormat:@"M:%s, L:%d.", __func__, __LINE__]#define PFUNCINF(x) @"%@|%@", FUNCINF, x#define PPFUNCINF(x1, x2) @"%@|%@|%@", FUNCINF, x1, x2#define PPPFUNCINF(x1, x2, x3) @"%@|%@|%@|%@", FUNCINF, x1, x2, x3
For example, the following code is called in the applicationDidFinishLaunching method of AppDelegate:
Use the DDLogError of the NSLog and Cocoa Lumberjack Log frameworks respectively (the parameters are the same as those of NSLog ):
NSLog (PFUNCINF (@ "Start Operation"); NSLog (PPFUNCINF (@ "Operation 1", @ 123); NSLog (PPPFUNCINF (@ "Operation 2 ", @ "sub-operation 1", @ "result 1"); // It is directly used in the Log of Cocoa Lumberjack for DDLogError (PPFUNCINF (@ "Operation 3 ", @ "error 1 "));
Output Log (M indicates the method name, and L indicates the number of rows ):
M:-[AppDelegate applicationDidFinishLaunching:], L: 60. | start operation M:-[AppDelegate applicationDidFinishLaunching:], L: 61. | operation 1 | 123 M:-[AppDelegate applicationDidFinishLaunching:], L: 62. | operation 2 | suboperation 1 | result 1 M:-[AppDelegate applicationDidFinishLaunching:], L: 64. | operation 3 | Error 1
Master haomeng is devoted to his contribution and respects the author's Labor achievements. Do not repost them.
If the article is helpful to you, you are welcome to donate to the author, support haomeng master, the amount of donation is free, focusing on your mind ^_^
I want to donate: Click to donate
Cocos2d-X source code download: point I send
Game official download: http://dwz.cn/RwTjl
Game video preview: http://dwz.cn/RzHHd
Game Development blog: http://dwz.cn/RzJzI
Game source code transfer: http://dwz.cn/Nret1
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.