在XCode中,是否有一种方法可以在调用NSLog时禁用调试器控制台中显示的时间戳? [英] In XCode, is there a way to disable the timestamps that appear in the debugger console when calling NSLog?

查看:236
本文介绍了在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
...

我有没有使用这个前缀,它占用了很多空间。我有一种感觉,它是硬编码到苹果的日志记录系统,但只要有一个解决方案:

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];
    [formattedString release];
}

显然,修改它添加换行符或使用较短的前缀等。 ..

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天全站免登陆