關於Debug下的Log打印問題

     在項目中爲了調試常常會用到Log打印,好比打印當前方法__func__, 對象,地址等等,因此項目最後每次運行調試控制檯滿滿的都是打印日誌,到release發佈的時候,顯然不太合適,這裏其實能夠用一個簡單的宏來解決。函數

1 #ifdef DEBUG
2 
3 #define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )//分別是方法地址,文件名,在文件的第幾行,自定義輸出內容
4 
5 #else
6 
7 #define DLog(...)
8 
9 #endif

 

     注意在#else後,也就是release中一開始定義成NSLog(...)會報錯: Implicit declaration of function 'DLog' is invalid in C99。spa

 

緣由: Release版本下所定義的DLog就成了一個空函數,在連接的是時候會報錯。調試

 

參考:  http://stackoverflow.com/questions/29234725/implicit-declaration-of-function-dlog-is-invalid-in-c99日誌

相關文章
相關標籤/搜索