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

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

    NSLog() is what is doing that, not the debugger console.

    The easiest way to avoid it is to not use NSLog at all. You could use fprintf(), but that is a pain in that it doesn't support %@ format types.

    I generally write a function for this:

    void MyLog(NSString *format, ...) {
        va_list args;
        va_start(args, format);
        NSString *formattedString = [[NSString alloc] initWithFormat: format
                                                      arguments: args];
        va_end(args);
        [[NSFileHandle fileHandleWithStandardOutput]
            writeData: [formattedString dataUsingEncoding: NSNEXTSTEPStringEncoding]];
    
    }
    

    Obviously, modify it to add a newline or use a shorter prefix, etc...

    (Fixed the stray ctrl-b)

提交回复
热议问题