如何摆脱 NSLog 中的所有这些垃圾?

2024-04-08

当我使用

NSLog(@"fooBar")

它打印出很多我不想要的东西:

2009-09-03 13:46:34.531 MyApp[3703:20b] fooBar

有没有办法在没有这个大前缀的情况下将某些内容打印到控制台? 我想在控制台中绘制一张桌子和其他一些东西,因此空间至关重要......


这是来自 borkware.com 的 Mark Dalrymple

http://borkware.com/quickies/single?id=261 http://borkware.com/quickies/single?id=261

更安静的 NSLog(常规 -> 黑客)[永久链接]

// NSLog() writes out entirely too much stuff.  Most of the time I'm
// not interested in the program name, process ID, and current time
// down to the subsecond level.
// This takes an NSString with printf-style format, and outputs it.
// regular old printf can't be used instead because it doesn't
// support the '%@' format option.

void QuietLog (NSString *format, ...)
{
  va_list argList;
  va_start (argList, format);
  NSString *message = [[[NSString alloc] initWithFormat: format
                                              arguments: argList] autorelease];
  printf ("%s", [message UTF8String]);
  va_end  (argList);

} // QuietLog
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何摆脱 NSLog 中的所有这些垃圾? 的相关文章

随机推荐