Shimen the main contribution, respect the work of the author, please do not reprint.
If the article is helpful to you, you are welcome to donate to the author, support the Shimen, donate the amount at random, ^_^
I want to donate: Click Donate
Cocos2d-x source Download: Dot I teleport
Games Official Download:HTTP://DWZ.CN/RWTJL
Game video preview:http://dwz.cn/RzHHd
Game Development Blog:Http://dwz.cn/RzJzI
Game Source transfer:Http://dwz.cn/Nret1
About log, printing the current function is nothing more than _cmd, __func__, __function__, __pretty_function__, in Xcode _cmd will return a Sel object,
And all that's left is the C/C + + compiler's definition, so it's going to go back to the string, and the results are all the same, and there might be a small difference between the compilers.
Obviously behind the __func__ series is better than _cmd , relative to the Objective-c type of method calls,
Not only does he display the method name, but it also displays the type, with __line__, which can pinpoint the location of the log in the code.
such as this:
@implementationmyclass+ (void) doo{//__func__, __function__, __pretty_function__, all the same . NSLog(@ "Method:%s, line:%d.", __func__, __line__);}@endWill output:
Method: +[myclass Doo], line:16.
We can also define some macros to be used quickly in nslog or other log frames, such as:
#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, suppose the following code is called in the Applicationdidfinishlaunching method of Appdelegate:
Use the ddlogerror of the NSLog and Cocoa lumberjack Log frames respectively (parameters and NSLog):
NSLog(Pfuncinf(@ "Start operation"));NSLog(Ppfuncinf(@ "Action 1", @123));NSLog(Pppfuncinf(@ "Action 2", @ "Sub-action 1", @ "Result 1"));//used directly in the log of Cocoa lumberjackDdlogerror(Ppfuncinf(@ "Action 3", @ "Error 1"));
Output log (M for method name, L for number of rows):
M:-[appdelegate applicationdidfinishlaunching:], l:60.| Start Operation M:-[appdelegate applicationdidfinishlaunching:], l:61.| Operation 1|123m:-[appdelegate Applicationdidfinishlaunching:], l:62.| Operation 2| 1| results 1m:-[appdelegate applicationdidfinishlaunching:], l:64.| Operation 3| Error 1
Shimen the main contribution, respect the work of the author, please do not reprint.
If the article is helpful to you, you are welcome to donate to the author, support the Shimen, donate the amount at random, ^_^
I want to donate: Click Donate
Cocos2d-x source Download: Dot I teleport
Games Official Download:HTTP://DWZ.CN/RWTJL
Game video preview:http://dwz.cn/RzHHd
Game Development Blog:Http://dwz.cn/RzJzI
Game Source transfer:Http://dwz.cn/Nret1
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS development uses more code-positioned log