nslog 宏定义输出 IOS

自己改写了网络上面的nslog宏定义功能,感觉很好用,推荐给大家:

首先,在-Prefix.pch文件中加入如下代码:

#ifdef DEBUG
#  define mLOG(fmt, ...) do {                                            \
        NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \
        NSLog((@"< FILE:%@; LINE:%d; FUNC:%s > --: " fmt), [file lastPathComponent], __LINE__, __func__, ##__VA_ARGS__); \
    } while(0)
#else
#  define mLOG(...)
#endif

如果你没有使用ARC,则为下面代码:

#ifdef DEBUG
#  define mLOG(fmt, ...) do {                                            \
        NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \
        NSLog((@"< FILE:%@; LINE:%d; FUNC:%s > --: " fmt), [file lastPathComponent], __LINE__, __func__, ##__VA_ARGS__); \
        [file release]; \
    } while(0)
#else
#  define mLOG(...)
#endif

编译一下,就可以在项目任何位置使用mLOG这个代码了如下:

    NSArray *arrtest = [[NSArray alloc] initWithObjects:@"one", @"tow", @"three", @"four", nil];
    mLOG(@"%@", arrtest);
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    mLOG(@"We all good friends.");

输出如下:

2014-05-15 12:20:14.063 ATMChaoRenJieKe1971[15222:60b] < FILE:NewsViewController.m; LINE:88; FUNC:-[NewsViewController viewDidLoad] > --: (
    one,
    tow,
    three,
    four
)
2014-05-15 12:20:14.067 ATMChaoRenJieKe1971[15222:60b] < FILE:NewsViewController.m; LINE:93; FUNC:-[NewsViewController viewWillAppear:] > --: We all good friends.

可以看出,方便使用还简洁,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值