问题描述
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 时出现在调试器控制台中的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!