如何摆脱所有这些垃圾在NSLog? [英] How to get rid of all this garbage in NSLog?

查看:121
本文介绍了如何摆脱所有这些垃圾在NSLog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用

  NSLog(@fooBar)
pre>

它输出了很多我不想要的东西:

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

有一种方法打印的东西到控制台没有这个大前缀?
我想在控制台中绘制一个表和其他一些东西,这样空间是至关重要的...

解决方案

这是来自borkware.com的Mark Dalrymple。



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



A Quieter NSLog(General-> Hacks)[permalink] p>

  // NSLog()写出太多的东西。大多数时候我是
//对程序名称,进程ID和当前时间不感兴趣
//下降到子级别。
//这需要一个带有printf风格格式的NSString,并输出它。
//不能使用正常的旧printf,因为它不是
//支持'%@'格式选项。

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


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

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

A Quieter NSLog (General->Hacks) [permalink]

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

这篇关于如何摆脱所有这些垃圾在NSLog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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