在 Xcode 中,有没有办法在调用 NSLog 时禁用出现在调试器控制台中的时间戳? [英] In Xcode, is there a way to disable the timestamps that appear in the debugger console when calling NSLog?

查看:25
本文介绍了在 Xcode 中,有没有办法在调用 NSLog 时禁用出现在调试器控制台中的时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 的调试器控制台可以很容易地查看我的应用使用 NSLog() 发出的任何调试消息,但它总是在它们上面加上时间戳前缀:

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:

2009-08-30 04:54:48.128 MyApp[94652:a0f] some log message
2009-08-30 04:54:50.647 MyApp[94652:a0f] another log message
...

这个前缀我没用,而且占用很多空间.我感觉它被硬编码到 Apple 的日志系统中,但以防万一有解决方案:

I have no use for this prefix, and it takes up a lot of room. I have a feeling it is hard-coded into Apple's logging system, but just in case there is a solution out there:

我可以让调试器控制台向我显示没有时间戳前缀的日志消息吗?

Can I have the debugger console show me log messages without the timestamp prefix?

这样的东西会很完美:

some log message
another log message
...

推荐答案

NSLog() 是这样做的,而不是调试器控制台.

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

避免它的最简单方法是根本不使用 NSLog.您可以使用 fprintf(),但很痛苦,因为它不支持 %@ 格式类型.

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...

(修正了流浪的 ctrl-b)

(Fixed the stray ctrl-b)

这篇关于在 Xcode 中,有没有办法在调用 NSLog 时禁用出现在调试器控制台中的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆