简体   繁体   English

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

[英]How to get rid of all this garbage in NSLog?

When I use 我用的时候

NSLog(@"fooBar")

it prints out a lot of stuff I don't want: 它打印出很多我不想要的东西:

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

Is there a way to print something to the console without this big prefix? 有没有办法在没有这个大前缀的情况下将某些内容打印到控制台? I want to draw a table and some other things in the console so that space is crucial... 我想在控制台中画一张桌子和其他东西,这样空间才是至关重要的......

This is from Mark Dalrymple at borkware.com 这是来自borkware.com的Mark Dalrymple

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

A Quieter NSLog (General->Hacks) [permalink] 更安静的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

This is a variation on the borkware quickies: http://cocoaheads.byu.edu/wiki/a-different-nslog . 这是borkware quickies的一个变种: http ://cocoaheads.byu.edu/wiki/a-different-nslog。 It prints the file and line number of where the log takes place. 它打印日志发生的文件和行号。 I use it all the time. 我用它所有的时间。

NSLog just prints to strerr. NSLog只是打印到strerr。 Use fprintf instead. 请改用fprintf。

fprintf(stderr, "foobar");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM