Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to clear NSLog Output?

Tags:

iphone

nslog

I have been googling from last couple of hours for finding that is there any way to clear NSLog output using code or not?

Like we have clrscr() in c. So if we are trying to print something which we want to focus most and there is lots of log printin there we can put that code there and get keep our desire log on top for easy searching. This can be done by putting breakpoint on my NSLog line and than click on clear console. but question is is there a way to achive this programatically?

I found few question on stack overflow but I din't satisfied with answer like this is saying that I can disable log for release mode etc.

Or I can use DLog, ALog or ULog as requirement but my question is different..

Any one can help me in this?

Thanks in advance :)

like image 445
Kapil Choubisa Avatar asked May 22 '12 12:05

Kapil Choubisa


1 Answers

You can use a conditional breakpoint to simulate it. Define a function like this in your code:

int clear_console()
{
    NSLog(@"\n\n\n\n\n\n\n\n");
}

Then, when you want to clear the console just add a breakpoint before the NSLog with this condition:

  • Condition: 1 > 0
  • Action: Debugger Command expr (int) clear_console()
  • Options: Automatically continue after evaluating Check it to skip the pause.

enter image description here

Tested with Xcode 4.3.2 and lldb.

Previous answer:

AFAIK, no, there isn't.

Just in case you're not doing it yet, you can create custom macros to format the output to highlight what you want.

Define macros like this:

#define CLEAR(...)          NSLog(@"\n\n\n\n\n\n") /* enough \n to "clear" the console */
#define WTF(...)            CLEAR();NSLog(@"!!!!!!!!!!!!!!");NSLog(__VA_ARGS__)
#define TRACE(__message__)  NSLog(@">>>>>>>>>>>>>>> %@ <<<<<<<<<<<<<<<<<<<", __message__)

Then:

WTF(@"This should't be here object: %@", theObject);
...
TRACE(@"Start Encoding");
...

It's not what you want but it pretty much solves the problem. You'll end up with your own set of macros with custom prefixes easily scannable in the console output.

like image 63
djromero Avatar answered Sep 28 '22 08:09

djromero