欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

DEBUG

程序员文章站 2022-05-10 22:58:03
...
//打印
#if DEBUG
#define DEBUGLOG(format, ...) do {\
fprintf(stderr, "-----------------------------------------\n");             \
fprintf(stderr, "File: %s\nFunc: %s\nLine: %d / Time: [%s]\n",         \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],  \
__func__, __LINE__, __TIME__);                                              \
fprintf(stderr, "Format:\n %s \n",                                          \
[[NSString stringWithFormat:format, ##__VA_ARGS__] UTF8String]);            \
fprintf(stderr, "-----------------------------------------\n\n");           \
} while (0)

#define _po(o) DEBUGLOG(@"%@", (o))
#define _pn(o) DEBUGLOG(@"%d", (o))
#define _pf(o) DEBUGLOG(@"%f", (o))
#define _ps(o) DEBUGLOG(@"CGSize: {%.0f, %.0f}", (o).width, (o).height)
#define _pr(o) DEBUGLOG(@"CGRect: {{%.0f, %.0f}, {%.0f, %.0f}}", (o).origin.x, (o).origin.y, (o).size.width, (o).size.height)

#define OBJ(obj)  DEBUGLOG(@"%s: %@", #obj, [(obj) description])

#define MARK    DEBUGLOG(@"\nMARK: %s, %d", __PRETTY_FUNCTION__, __LINE__)
#else
#define DEBUGLOG(format, ...) nil
#endif