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

前端 未结 8 2310
别跟我提以往
别跟我提以往 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 15:19

    ARC Version:

    void NFLog(NSString *format, ...)
    {
        va_list args;
        va_start(args, format);
        NSString *formattedString = [NSString stringWithFormat:format, args];
        formattedString = [formattedString stringByAppendingString:@"\n"];
        va_end(args);
        [[NSFileHandle fileHandleWithStandardOutput] writeData: [formattedString dataUsingEncoding: NSUTF8StringEncoding]];
    }
    

    update:

    What I am doing is add this code to xxx-Prefix.pch then you can use it anywhere:

    #define newLine         do { [(NSFileHandle*)[NSFileHandle fileHandleWithStandardOutput] writeData:[@"\n" dataUsingEncoding: NSUTF8StringEncoding]]; } while(0);
    #define NFLog(args,...) do { [(NSFileHandle*)[NSFileHandle fileHandleWithStandardOutput] writeData:[[NSString stringWithFormat:args, ##__VA_ARGS__] dataUsingEncoding: NSUTF8StringEncoding]]; } while(0); newLine
    

    and if you want NSLog back:

    #define NFLog(args,...) NSLog(args,##__VA_ARGS__)
    

提交回复
热议问题