Objective C 总结(十五):Logging

NSMutableArray *someObject = [NSMutableArray array];
NSLog(@"%s:%d someObject=%@", __func__, __LINE__, someObject);
[someObject addObject:@"foo"];
NSLog(@"%s:%d someObject=%@", __func__, __LINE__, someObject);


Table 1  Preprocessor macros and for logging in C/C++/Objective-C.

Macro

Format Specifier

Description

__func__

%s

Current function signature.

__LINE__

%d

Current line number in the source code file.

__FILE__

%s

Full path to the source code file.

__PRETTY_FUNCTION__

%s

Like __func__, but includes verbose type information in C++ code.

Table 2  Expressions for logging in Objective-C.

Expression

Format Specifier

Description

NSStringFromSelector(_cmd)

%@

Name of the current selector.

NSStringFromClass([self class])

%@

Name of the current object's class.

[[NSString stringWithUTF8String:__FILE__] lastPathComponent]

%@

Name of the source code file.

[NSThread callStackSymbols]

%@

NSArray of the current stack trace as programmer-readable strings. For debugging only, do not present it to end users or use to do any logic in your program.

posted @ 2013-08-09 15:41  万有引用  阅读(225)  评论(0编辑  收藏  举报