RSS

XCode Feature Proposal: Linking NSLog to Code

If you’ve ever used NSLogs to help in your debug process, this description probably fits your process. You add a log statement in this code over here. You look further at the code and find that the problem is probably elsewhere, so you go down the chain of files and add more NSLogs. You do this for awhile, and you’ve built up a sometimes large list of NSLogs. And sometimes what you log might be equivalent to other messages. Now looking at your console logs, you see all the statements, and you don’t immediately know where those messages are originating from. This could also arise if you leave your log statements in and come back to the code 3 months later.

Your solution right now is to pop up the global search window, copy and paste part of the message in, and then track down which log statement that came from. This can amount to a lot of work after awhile.

Instead, I propose that the XCode team add a very small feature to NSLog and their console that hyperlinks the outputted NSLog message in the console to the file and line number where it was generated. It would be great for developers to have a quick link they can follow that shows exactly where their log statements are coming from.

The code to add this would be relatively minor. For instance, you only need to write a one line macro to fix NSLog.

#define NSLog2(...) NSLog([NSString stringWithFormat:@"<!%s,%s!> %@", __FILE__, __LINE__, [NSString stringWithFormat: __VA_ARGS__]])

A call to NSLog2 will simply call NSLog and prepend the file name and line number. For example:

NSLog2(@"Hello %i %@", 500, [NSArray arrayWithObject:@"hi"]);
/* Prints to console:
2009-10-22 17:27:30.809 Todos[22446:a0f] <!/Users/deb/repositories/todos/AppController.m,22!> Hello 500 (
    hi
)
*/

In XCode, they would need to add a bit of code to the console that would look for strings formatted like . Then, they can strip everything between from the console method. They would the generate a clickable link for the message that would open up that source file and position the cursor at the line number. Very simple and incredible useful.

Thoughts? Good or bad idea? Do you have a hack to implement this?

  • ashishy
    Homestead Maid Service has been providing quality Toronto House Cleaning services for over 24 years.

    _________
    Ashish

    http://homesteadmaid.com
blog comments powered by Disqus
« Inline SCM: A Proposal For A Better SVN or Git