覆盖NSLOG

时间:2017-04-06 12:54:09

标签: ios objective-c iphone

我想覆盖现有的NSLog机制。

NSLog应该有不同的模式.NSLOG(,“描述”);  可以是1,2或3中的数字来表示日志级别是否为“关键”,“主要”或“次要”。

如果loglevel = 1,我想要Overridden NSLOG以及函数名和行号。

为什么打印i = 5未在下面的示例代码中打印?如何解决这个问题?

#define NSLog(loglevel, ...) \
 if(loglevel == 1) \
   NSLog( @"%s [Line %d] %s", __PRETTY_FUNCTION__, __LINE__, 
       ##__VA_ARGS__);


 - (BOOL)application:(UIApplication *)application 
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
       // Override point for customization after application launch.
        NSLog(1,"Hello how r u");
        int i=5;
        NSLog(1,"Printing i=%d", i);

        return YES;
  }

输出

  

[AppDelegate应用程序:didFinishLaunchingWithOptions:] [第32行]   大家好你好06-06 15:15:17.303 LogLevel [3620:160181]    - [AppDelegate应用程序:didFinishLaunchingWithOptions:] [第34行]打印i =%d

0 个答案:

没有答案
相关问题