In Xcode, is there a way to disable the timestamps that appear in the debugger console when calling NSLog?

前端 未结 8 2311
别跟我提以往
别跟我提以往 2020-12-02 14:30

Xcode\'s debugger console makes it easy to see any debugging messages my app sends out using NSLog(), but it always sticks a timestamp prefix on them:



        
8条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 14:58

    Define a macro

    #if __has_feature(objc_arc)
      #define MDLog(format, ...) CFShow((__bridge CFStringRef)[NSString stringWithFormat:format, ## __VA_ARGS__]);
    #else
      #define MDLog(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
    #endif
    

    And use this macro in you code like

    NSLog(@"some log message");
    MDLog(@"some log message");
    

    Here is the output of console

    NSLog->2014-01-28 10:43:17.873 TestApp[452:60b] some log message
    MDLog -> some log message


    P.S.

    If anyone wants Custom Logs which gives you more info like method name / line number etc. can download the open source MLog.h on GitHub.

提交回复
热议问题